Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SlackHandler doesn’t work #729

Closed
r3nat opened this issue Feb 8, 2016 · 8 comments
Closed

SlackHandler doesn’t work #729

r3nat opened this issue Feb 8, 2016 · 8 comments
Labels

Comments

@r3nat
Copy link

r3nat commented Feb 8, 2016

monolog 1.15.0, tried 1.17.1

use Monolog\Handler\SlackHandler;
use Monolog\Logger;

$Logger = new Logger("Whatever");
$Handler = new SlackHandler($token, "@renat");
$Logger->pushHandler($Handler);

$Logger->emerg("Hey, " . date("H:i:s"));

30-70% of messages are lost without error.
Adding fread($this->resource, 8192); to the end of SocketHandler->writeToSocket fixes the problem, although it looks like dirty hack.

@Aliance
Copy link
Contributor

Aliance commented Feb 8, 2016

+1

@GeeH
Copy link

GeeH commented Feb 18, 2016

+1 :trollface:

@pprishchepa
Copy link

+1

@stloyd
Copy link

stloyd commented Mar 1, 2016

Unfortunatelly can confirm that if amount of logs is quite big, slack handler loses those messages.

@pprishchepa
Copy link

@stloyd In my case it is not correlate with amount of logs. It's about 1 message per 10 seconds.

@r3nat Adding fread($this->resource, 8192); helps me too, thanks.

@Seldaek
Copy link
Owner

Seldaek commented Mar 1, 2016

I don't really see what the fread does there.. Can someone try and explain? Do you add it at the very end or does it also work around SocketHandler line 294 just after the fwrite?

Also could you maybe var_dump what the fread() returns to see what is being sent back by slack that we need to acknowledge for it to not drop messages?

Another fix would be to add a fread() inside SlackHandler::write before closing the handler I guess. I don't really want to apply this blindly to all SocketHandler derivatives as it might cause issues.

@Seldaek Seldaek added the Bug label Mar 1, 2016
@r3nat
Copy link
Author

r3nat commented Mar 2, 2016

I think if socket closes too early, than slack will not process request.
Adding usleep(10000) instead of fread does the trick too.

Result of fread:

string(1137) "HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 356
Connection: keep-alive
Access-Control-Allow-Origin: *
Cache-Control: private, no-cache, no-store, must-revalidate
Content-Security-Policy: referrer no-referrer;
Date: Wed, 02 Mar 2016 17:48:54 GMT
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Pragma: no-cache
Server: Apache
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Vary: Accept-Encoding
X-Accepted-OAuth-Scopes: chat:write:bot,post
X-Content-Type-Options: nosniff
X-OAuth-Scopes: identify,read,post,client,admin
X-XSS-Protection: 0
X-Cache: Miss from cloudfront
Via: 1.1 1228e077cd8e3d045c8d3f88beaa5abd.cloudfront.net (CloudFront)
X-Amz-Cf-Id: daiAXEapRDWtmBEVEaIuuuCrocmdZL6Z6ZE_a8TIMRVX8Y6ZtPCGYQ==

{"ok":true,"channel":"D02AF3J3X","ts":"1456940934.000002","message":{"text":"","username":"Monolog","attachments":[{"fallback":"Hey, 20:48:54","id":1,"color":"d00000","fields":[{"title":"Message","value":"Hey, 20:48:54","short":false},{"title":"Level","value":"EMERGENCY","short":true}]}],"type":"message","subtype":"bot_message","ts":"1456940934.000002"}}"

@lesaff
Copy link

lesaff commented Mar 3, 2016

To confirm @r3nat, this works 👍
SlackHandler.php, line 236

    /**
     * {@inheritdoc}
     *
     * @param array $record
     */
    protected function write(array $record)
    {
        parent::write($record);
        usleep(10000); // Delay before socket close
        $this->closeSocket();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants