-
Notifications
You must be signed in to change notification settings - Fork 112
fix(buffer): Reject envelope when buffer is down #5746
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b32e9bf
fix(buffer): Reject envelope when buffer is down
jjbayer f5c6982
test: Add integration test for graceful shutdown HTTP behavior
jjbayer ade7db0
reproduce
jjbayer 7e29153
catch shutdown explicitly
jjbayer 6f8eee8
update test
jjbayer 440464f
lint
jjbayer eb5a1fe
fix memory test
jjbayer 1b91abd
changelog
jjbayer 249aa8b
Merge branch 'master' into fix/queue-failed
jjbayer 9bafe35
test: log response body for flaky test
jjbayer 53a13fa
Merge remote-tracking branch 'origin/master' into fix/queue-failed
jjbayer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import json | ||
| import os | ||
| import signal | ||
| import socket | ||
| import time | ||
| import tempfile | ||
|
|
||
|
|
||
| def test_graceful_shutdown(mini_sentry, relay): | ||
| """ | ||
| On SIGTERM, relay completes any in-flight HTTP requests before shutting down. | ||
| New connections are rejected once the TCP listener closes. | ||
|
|
||
| We test this by holding a request in-flight at the TCP level: send the HTTP | ||
| headers and the first byte of the body, then send SIGTERM, then send the rest | ||
| of the body. Relay must process and respond to the request before it exits. | ||
| """ | ||
| project_id = 42 | ||
| mini_sentry.add_basic_project_config(project_id) | ||
|
|
||
| with tempfile.TemporaryDirectory() as db_dir: | ||
| db_file_path = os.path.join(db_dir, "database.db") | ||
|
|
||
| relay = relay( | ||
| mini_sentry, | ||
| options={ | ||
| "limits": {"shutdown_timeout": 5}, | ||
| "spool": {"envelopes": {"path": db_file_path}}, | ||
| }, | ||
| ) | ||
|
|
||
| host, port = relay.server_address | ||
| dsn_key = relay.get_dsn_public_key(project_id) | ||
|
|
||
| body = json.dumps({"message": "in-flight during shutdown"}).encode() | ||
| request = ( | ||
| f"POST /api/{project_id}/store/ HTTP/1.1\r\n" | ||
| f"Host: {host}:{port}\r\n" | ||
| f"Content-Type: application/json\r\n" | ||
| f"X-Sentry-Auth: Sentry sentry_version=7, sentry_key={dsn_key}\r\n" | ||
| f"Content-Length: {len(body)}\r\n" | ||
| f"Connection: close\r\n" | ||
| f"\r\n" | ||
| ).encode() + body | ||
|
|
||
| # Open a raw TCP connection and send everything up to the last byte. | ||
| # Relay is now holding the connection open waiting for the body to complete — | ||
| # the request is in-flight. | ||
| sock = socket.create_connection((host, port)) | ||
| sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) | ||
| sock.sendall(request[:-1]) | ||
|
|
||
| # Trigger graceful shutdown while the request is in-flight. | ||
| relay.process.send_signal(signal.SIGTERM) | ||
| time.sleep(0.05) | ||
|
|
||
| # Complete the request — relay will respond with Service Unavailable. | ||
| sock.sendall(request[-1:]) | ||
|
|
||
| sock.settimeout(10) | ||
| response = b"" | ||
| while chunk := sock.recv(4096): | ||
| response += chunk | ||
| sock.close() | ||
|
|
||
| assert b"HTTP/1.1 503" in response | ||
|
|
||
| # After relay exits, new connections are refused. | ||
| relay.wait_for_exit(timeout=10) | ||
| try: | ||
| socket.create_connection((host, port)) | ||
| assert False, "Expected connection to be refused after relay exited" | ||
| except ConnectionRefusedError: | ||
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Downgraded from error to warning here because events are not necessarily lost, as long as the client retries 503s. We will still see the warning in Sentry.