You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I am implementing a BidiStream which maps messages back and forth with a separate service that is similar to a BiDiStream (technically it's a websocket service). I couldn't find a way to receive messages from the other service in a separate goroutine since it would have no way to terminate a stream.Receive call AFAICT.
For an error case I want to end this BiDiStream, but with stream.Receive() blocking for a message, it doesn't seem to be possible. While a client has close methods on the stream, server does not.
Describe the solution you'd like
Either is fine
Add Close(error) on BiDiStream. Pending Receive() will return with the error. If error is not accepted by Close, then a generic error that can be errors.Is can be returned instead
Add ctx to Receive (Likely a new method like ReceiveContext(ctx), when the context is canceled the receive method returns. This was brought up in Support context.Context in BidiStream's Receive() #735 but IIUC it was a somewhat different case than this one. But I guess with current golang stdlib this may not be implementable (more direct access to the http2 stream would be needed for proper cancellation)
Describe alternatives you've considered
If you've proposed a solution, are there any alternatives? Why are they worse
than your preferred approach?
Always call stream.Receive in another goroutine, instead of vice-versa. In my example, sess does have a Close method which would cause sess.Receive() in the main goroutine to return with error, similar to my proposal. And if it was otherwise a connect-go BidiStream client, it would also be closeable. I don't know if there is some hidden "always receive client messages in another goroutine" connect best practice, but intuitively there shouldn't be I guess.
Additional context
Add any other context or screenshots about the feature request here.
Is your feature request related to a problem? Please describe.
I am implementing a
BidiStreamwhich maps messages back and forth with a separate service that is similar to aBiDiStream(technically it's a websocket service). I couldn't find a way to receive messages from the other service in a separate goroutine since it would have no way to terminate astream.Receivecall AFAICT.For an error case I want to end this
BiDiStream, but withstream.Receive()blocking for a message, it doesn't seem to be possible. While a client has close methods on the stream, server does not.Describe the solution you'd like
Either is fine
Close(error)onBiDiStream. PendingReceive()will return with theerror. Iferroris not accepted byClose, then a generic error that can beerrors.Iscan be returned insteadctxtoReceive(Likely a new method likeReceiveContext(ctx), when the context is canceled the receive method returns. This was brought up in Support context.Context in BidiStream's Receive() #735 but IIUC it was a somewhat different case than this one. But I guess with current golang stdlib this may not be implementable (more direct access to the http2 stream would be needed for proper cancellation)Describe alternatives you've considered
If you've proposed a solution, are there any alternatives? Why are they worse
than your preferred approach?
Always call
stream.Receivein another goroutine, instead of vice-versa. In my example,sessdoes have aClosemethod which would causesess.Receive()in the main goroutine to return witherror, similar to my proposal. And if it was otherwise a connect-goBidiStreamclient, it would also be closeable. I don't know if there is some hidden "always receive client messages in another goroutine" connect best practice, but intuitively there shouldn't be I guess.Additional context
Add any other context or screenshots about the feature request here.