-
Notifications
You must be signed in to change notification settings - Fork 5
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
[protocolv2] Handle invalid requests and internal server errors #203
Conversation
@@ -399,10 +395,6 @@ class RiverServer<Services extends AnyServiceSchemaMap> | |||
|
|||
const onHandlerError = (err: unknown, span: Span) => { | |||
const errorMsg = coerceErrorString(err); | |||
this.log?.error( |
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.
stopped logging here, it's an application-level error, clients can choose to log this
@@ -558,11 +551,11 @@ class RiverServer<Services extends AnyServiceSchemaMap> | |||
|
|||
break; | |||
default: | |||
this.log?.warn( | |||
this.log?.error( |
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.
promoted to error, this should never happen.
this.transport.sessionHandshakeMetadata.get(session); | ||
if (!sessionMetadata) { | ||
const errMessage = `session doesn't have handshake metadata`; | ||
this.log?.error(errMessage, { |
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.
promoted this from warn to error, as it's an internal error, we should never hit this in theory.
|
||
if (!initMessage.serviceName) { | ||
const errMessage = `missing service name in stream open message`; | ||
this.log?.warn(errMessage, { |
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.
demoted to warn, it's a client problem.
|
||
if (!Value.Check(procedure.init, initMessage.payload)) { | ||
const errMessage = `procedure init failed validation`; | ||
this.log?.warn(errMessage, { |
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.
demoted to warn, it's a client problem.
validationErrors.push(...Value.Errors(procedure.input, msg.payload)); | ||
} | ||
|
||
this.log?.warn(errMessage, { |
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.
demoted to warn, it's a client problem.
@@ -315,23 +287,47 @@ class RiverServer<Services extends AnyServiceSchemaMap> | |||
} | |||
|
|||
if (inputReader.isClosed()) { | |||
this.log?.error('Received message after input stream is closed', { | |||
this.log?.warn('Received message after input stream is closed', { |
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.
demoted to warn, it's a client problem.
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.
is this an invariant violation / should we add that as a tag?
@@ -293,7 +264,8 @@ class RiverServer<Services extends AnyServiceSchemaMap> | |||
code: ABORT_CODE, | |||
message: 'Stream aborted, client sent invalid payload', | |||
}); | |||
this.log?.error('Got stream abort without a valid protocol error', { | |||
this.log?.warn('Got stream abort without a valid protocol error', { |
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.
demoted to warn, it's a client problem.
*/ | ||
session: Session<Connection>; // TODO: only expose a subset interface of session | ||
from: TransportClientId; |
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.
this feels like the only thing a service implementer would might need from a session
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.
lgtm
3b42ea6
to
3b43f71
Compare
3b43f71
to
6618a10
Compare
*/ | ||
session: Session<Connection>; // TODO: only expose a subset interface of session | ||
from: TransportClientId; |
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.
lgtm
@@ -315,23 +287,47 @@ class RiverServer<Services extends AnyServiceSchemaMap> | |||
} | |||
|
|||
if (inputReader.isClosed()) { | |||
this.log?.error('Received message after input stream is closed', { | |||
this.log?.warn('Received message after input stream is closed', { |
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.
is this an invariant violation / should we add that as a tag?
...loggingMetadata, | ||
clientId: this.transport.clientId, | ||
transportMessage: msg, | ||
validationErrors, |
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.
same here: maybe we want to tag this with invariant violation?
938b625
to
5f339e3
Compare
6618a10
to
04eaac6
Compare
## Why Clients can send invalid requests for many reasons, most commonly due to backwards incompatible server changes, server should handle those and send back a stream abort with it. ## What changed - Introduced `INTERNAL_RIVER_ERROR` code since some of the errors are invariant violations on the server - Split out stream request validation from stream handling - When we see a bad request, we send `INVALID_REQUEST` code with an abort bit - Made tracing `createHandlerSpan` accept tracing fields explicitly instead of a transport message some more changes that I'll note inline
## Why Clients can send invalid requests for many reasons, most commonly due to backwards incompatible server changes, server should handle those and send back a stream abort with it. ## What changed - Introduced `INTERNAL_RIVER_ERROR` code since some of the errors are invariant violations on the server - Split out stream request validation from stream handling - When we see a bad request, we send `INVALID_REQUEST` code with an abort bit - Made tracing `createHandlerSpan` accept tracing fields explicitly instead of a transport message some more changes that I'll note inline
## Why Clients can send invalid requests for many reasons, most commonly due to backwards incompatible server changes, server should handle those and send back a stream abort with it. ## What changed - Introduced `INTERNAL_RIVER_ERROR` code since some of the errors are invariant violations on the server - Split out stream request validation from stream handling - When we see a bad request, we send `INVALID_REQUEST` code with an abort bit - Made tracing `createHandlerSpan` accept tracing fields explicitly instead of a transport message some more changes that I'll note inline
Why
Clients can send invalid requests for many reasons, most commonly due to backwards incompatible server changes, server should handle those and send back a stream abort with it.
What changed
INTERNAL_RIVER_ERROR
code since some of the errors are invariant violations on the serverINVALID_REQUEST
code with an abort bitcreateHandlerSpan
accept tracing fields explicitly instead of a transport messagesome more changes that I'll note inline