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

fix(server): Support HTTP half-close connections #2089

Merged
merged 10 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Enforce rate limits for monitor check-ins. ([#2065](https://github.com/getsentry/relay/pull/2065))
- Allow rate limits greater than `u32::MAX`. ([#2079](https://github.com/getsentry/relay/pull/2079))
- Do not drop envelope when client closes connection. ([#2089](https://github.com/getsentry/relay/pull/2089))

**Features**:

Expand Down
2 changes: 1 addition & 1 deletion relay-server/src/actors/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Service for HttpServer {
.into_make_service_with_connect_info::<SocketAddr>();

let http_config = HttpConfig::new()
.http1_half_close(false)
.http1_half_close(true)
.http1_header_read_timeout(CLIENT_HEADER_TIMEOUT)
.http1_writev(true)
.http2_keep_alive_timeout(config.keepalive_timeout())
Expand Down
35 changes: 35 additions & 0 deletions tests/integration/test_envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,41 @@ def test_envelope(mini_sentry, relay_chain):
assert event["logentry"] == {"formatted": "Hello, World!"}


def test_envelope_close_connection(mini_sentry, relay):
"""Prematurely closing the TCP connection on the client side does not drop the envelope"""
import socket
import time

mini_sentry.add_basic_project_config(42)
dsn_key = mini_sentry.get_dsn_public_key(42, 0)
relay = relay(mini_sentry)

# Prepare POST data:
body_template = """{"event_id": "9ec79c33ec9942ab8353589fcb2e04dc","dsn": "https://%s:@sentry.io/42"}
{"type":"attachment","length":11,"content_type":"text/plain","filename":"hello.txt"}
Hello World
"""

# Run multiple times to cover potential test flakiness.
num_iterations = 10
for _ in range(num_iterations):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(relay.server_address)

body = body_template % dsn_key
req = f"""POST /api/42/envelope/ HTTP/1.1\r\nContent-Length: {len(body)}\r\n\r\n{body}""".encode()
sock.send(req)

time.sleep(0.0001) # Give relay time to start processing event

sock.close() # Close the connection

for _ in range(num_iterations):
envelope = mini_sentry.captured_events.get(timeout=1)
assert envelope
assert mini_sentry.captured_events.empty()


def test_envelope_empty(mini_sentry, relay):
relay = relay(mini_sentry)
PROJECT_ID = 42
Expand Down