Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Support threaded transport also for background or server processes #932

Closed
wants to merge 1 commit into from
Closed

Conversation

frietsch-ot
Copy link

We are running the raven python client inside of a (yes, very old school, I agree) CGI web application and would like to use a threaded transport, so that normal operation can continue while raven is working.

However, in rare but not rare enough cases, the CGI process is about to terminate before raven has sent all messages, and then, some output "Sentry is attempting to send... Hit Ctrl+C to abort" appears on stdout, which - lame old CGI - is the web page sent to the client. In worst case, the output is seen as (broken) HTTP headers, leading to interesting HTTP status codes from the web server.

To avoid the stdout output, I added some ThreadedBackgroundHTTPTransport, which uses the same timeout approach as the original ThreadedHTTPTransport, but simply doesn't print the Ctrl+C message. My updated test case uses both transports for complete test coverage, even though the change is rather boring.

Note: The overall diff is very small in fact, it's just that I had to change a lot of indent.

…d or server processes and does NOT use standard output.
@mattrobenolt
Copy link
Contributor

Would it help if we just wrote to stderr instead of stdout? Not sure if stderr would affect CGI output or not.

I think we should also detect isatty() here as well since prompting for Ctrl-C is silly if you don't have a TTY.

@frietsch-ot
Copy link
Author

Writing to stderr doesn't seem to be an optimal choice, as this output is written to the server error log then (but I don't consider this "wanna wait" to be a real error :-) ). Certain HTTP servers may create HTTP 500s when reading anything on stderr.

But: Checking sys.stdout.isatty() is a great idea, Matt! This indeed seems to be "False" in my CGI environment (and True otherwise, of course) and should solve my problem with a very very short diff to your original code.

Sadly, I'm not yet very experienced in pull requests on GitHub (I assume it's easier to create a new one from a fresh branch instead of trying to fix the original PR with another commit). How shall we proceed?

@frietsch-ot
Copy link
Author

Ok, I'll create a separate pull request with the isatty() approach, to get things forward 😃

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

Successfully merging this pull request may close these issues.

2 participants