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

Rhai supergraph response callback does not trigger when a broken pipe is encountered #4590

Closed
danpayne17 opened this issue Feb 2, 2024 · 0 comments · Fixed by #4770
Closed
Assignees
Labels
potentially-breaking Requires an incompatible change raised by user

Comments

@danpayne17
Copy link

Describe the bug
If the caller closes the connection before the router is done sending the response (e.g. broken pipe), the response callback of the supergraph lifecycle event is never triggered. This is an issue because in this callback, we use Rhai to do a number of things:

  1. set response headers (this obviously is irrelevant because the pipe is broken so the response isn't going to be sent so we don't need to set these headers)
  2. rewrite the errors array in response body, if present (also irrelevant b/c the response is not going to be sent to caller)
  3. set response context variables for use in telemetry instrumentation by response_context selectors (these need to be set in order for span tag attributes to be applied as expected; may be related to
    image)
  4. log the status of the response (e.g. call to n milliseconds to process for this operation name and resulted in these errors) (this is really important as this log statement actually drives Splunk dashboards and this log statement is never made b/c this lifecycle event isn't triggered)
  5. log the response body (not super critical but would be nice to still log the response body that would have been sent if the pipe weren't broken)

To Reproduce
Steps to reproduce the behavior:

  1. Configure router to execute Rhai scripts during supergraph response callback:
fn supergraph_service(service) {
  const response_callback = Fn("process_supergraph_response");
  service.map_response(response_callback);
}

fn process_supergraph_response(response) {
  print('executing fn process_supergraph_response()');
  tracing_handler::set_supergraph_response_headers(response);
  error_handler::rewrite_extensions_in_supergraph_response(response);
  error_handler::set_response_context_selector_values(response);
  logger::log_response_status(response);
  logger::log_response_body(response);
}
  1. Insert code into subgraph resolver so that it waits 10seconds before responding to requests from router
  2. Send request to router using curl
  3. Cancel request (ctrl-c) while subgraph is waiting to respond which induces a broken pipe error
  4. Observe that the process_supergraph_response was never called

Expected behavior
The response callback of the supergraph service is still executed when a broken pipe is encountered, just like other non-200 errors the router encounters (e.g. a 400 BAD REQUEST still executes the callback)

Router:

  • OS: Amazon Linux 2023
  • Version: 1.37.0

Additional context
None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
potentially-breaking Requires an incompatible change raised by user
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants