Skip to content

fix(pb-envoy): reduce round trips for ws connection#4603

Merged
MasterPtato merged 1 commit intomainfrom
04-09-fix_pb-envoy_reduce_round_trips_for_ws_connection
Apr 13, 2026
Merged

fix(pb-envoy): reduce round trips for ws connection#4603
MasterPtato merged 1 commit intomainfrom
04-09-fix_pb-envoy_reduce_round_trips_for_ws_connection

Conversation

@MasterPtato
Copy link
Copy Markdown
Contributor

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Copy Markdown
Contributor Author

MasterPtato commented Apr 10, 2026

@claude
Copy link
Copy Markdown

claude bot commented Apr 10, 2026

PR Review: fix(pb-envoy): reduce round trips for ws connection

This is a well-structured optimization that eliminates a blocking round trip during WebSocket connection establishment by moving version and envoy_key from an initial protocol message to URL query parameters. The concurrent tokio::try_join! is clean. A few issues are worth addressing.

BUG 1: is_serverless hardcoded to false in Conn
File: engine/packages/pegboard-envoy/src/conn.rs

The computed is_serverless value is correctly used to call report_success, but never propagated to the Conn struct (is_serverless: false is hardcoded). This means the guard in ws_to_tunnel_task.rs that calls pegboard::ops::envoy::expire only for serverful envoys on ToRivetStopping will incorrectly fire for serverless envoys too, since conn.is_serverless is always false. Fix: use is_serverless (the computed variable) in the struct literal.

BUG 2: Double util::timestamp::now() call for create_ts
File: engine/packages/pegboard-envoy/src/conn.rs

In the new-envoy branch of the DB transaction, create_ts is assigned from one call to timestamp::now(), but tx.write calls timestamp::now() again for the stored value. These two timestamps will differ. Since create_ts is later used to construct ActiveEnvoyKey, ActiveEnvoyByNameKey, and EnvoyLoadBalancerIdxKey, those keys will not match what was written to create_ts_key.
Fix: tx.write(&create_ts_key, create_ts)?

MINOR 1: Misleading metric name
File: engine/packages/pegboard-envoy/src/conn.rs

RECEIVE_INIT_PACKET_DURATION now measures namespace resolution time rather than the time to receive an init packet (no longer a blocking step). The name should be updated (e.g. NAMESPACE_RESOLVE_DURATION) to keep dashboards and alerts accurate.

MINOR 2: prepopulate_actor_names always Some in client
File: engine/sdks/rust/envoy-client/src/connection.rs

prepopulate_actor_names: Some(prepopulate_map) is sent even when the map is empty, triggering the write loop in handle_metadata unconditionally. Sending None when the map is empty avoids the unnecessary DB transaction.

NOTE: envoy_key now in URL query string

Moving envoy_key from a binary protocol message to a URL query parameter means it may appear in access logs on proxies or load balancers. Since these are server-to-server connections over TLS this is a low-risk trade-off, but worth auditing log retention and scrubbing policies to ensure keys are not persisted in plain-text logs.

Summary: The core optimization is sound and the protocol rename (ToRivetInit to ToRivetMetadata) is cleaner semantically. BUG 1 (is_serverless hardcode) and BUG 2 (double timestamp::now()) should be followed up on.

@MasterPtato MasterPtato mentioned this pull request Apr 11, 2026
11 tasks
@MasterPtato MasterPtato marked this pull request as ready for review April 11, 2026 22:07
@MasterPtato MasterPtato force-pushed the 04-09-fix_pb-envoy_reduce_round_trips_for_ws_connection branch from cd89bc9 to f4762f2 Compare April 12, 2026 19:42
@MasterPtato MasterPtato force-pushed the 04-09-fix_envoy-client_fix_handling_actor_event_ack branch from f171f60 to db25562 Compare April 12, 2026 19:42
@MasterPtato MasterPtato force-pushed the 04-09-fix_envoy-client_fix_handling_actor_event_ack branch from db25562 to c694cb5 Compare April 12, 2026 21:21
@MasterPtato MasterPtato force-pushed the 04-09-fix_pb-envoy_reduce_round_trips_for_ws_connection branch 2 times, most recently from 002100d to fc3149f Compare April 12, 2026 23:38
@MasterPtato MasterPtato force-pushed the 04-09-fix_envoy-client_fix_handling_actor_event_ack branch from c694cb5 to 91328b0 Compare April 12, 2026 23:38
@MasterPtato MasterPtato force-pushed the 04-09-fix_envoy-client_fix_handling_actor_event_ack branch from 91328b0 to 2a54f2e Compare April 13, 2026 00:20
@MasterPtato MasterPtato force-pushed the 04-09-fix_pb-envoy_reduce_round_trips_for_ws_connection branch from fc3149f to 26f63c1 Compare April 13, 2026 00:20
Copy link
Copy Markdown
Contributor Author

MasterPtato commented Apr 13, 2026

Merge activity

  • Apr 13, 12:21 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Apr 13, 12:29 AM UTC: Graphite rebased this pull request as part of a merge.
  • Apr 13, 12:30 AM UTC: @MasterPtato merged this pull request with Graphite.

@MasterPtato MasterPtato changed the base branch from 04-09-fix_envoy-client_fix_handling_actor_event_ack to graphite-base/4603 April 13, 2026 00:26
@MasterPtato MasterPtato changed the base branch from graphite-base/4603 to main April 13, 2026 00:27
@MasterPtato MasterPtato force-pushed the 04-09-fix_pb-envoy_reduce_round_trips_for_ws_connection branch from 26f63c1 to cfda19b Compare April 13, 2026 00:28
@MasterPtato MasterPtato merged commit 596e266 into main Apr 13, 2026
5 of 14 checks passed
@MasterPtato MasterPtato deleted the 04-09-fix_pb-envoy_reduce_round_trips_for_ws_connection branch April 13, 2026 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants