msquic icon indicating copy to clipboard operation
msquic copied to clipboard

Cannot receive message in stream_callback on server

Open lauix opened this issue 1 year ago • 8 comments

Describe the bug

client send a query request to server. when server received the request in the stream_callback function(event is QUIC_STREAM_EVENT_RECEIVE) , I used StreamSend function to send the response data to the client in the stream_callback function, and then the server-side donnot receive any requests.

Affected OS

  • [ ] Windows
  • [X] Linux
  • [ ] macOS
  • [ ] Other (specify below)

Additional OS information

No response

MsQuic version

main

Steps taken to reproduce bug

QUIC_STATUS msquic_stream_callback(HQUIC strm, void *context, QUIC_STREAM_EVENT *event) { QUIC_STATUS status = QUIC_STATUS_SUCCESS;

sample_comm_msquic_context *ctx = (sample_comm_msquic_context *)context;
sample_comm_msquic_share_info *msquic_share_info = (sample_comm_msquic_share_info *)ctx->user_data;

switch (event->Type) {
case QUIC_STREAM_EVENT_SEND_COMPLETE: {
    free(event->SEND_COMPLETE.ClientContext);
} break;
case QUIC_STREAM_EVENT_RECEIVE: {

     // build response data

     if (QUIC_FAILED(status = msquic_share_info->msquic_handle->api->StreamSend(strm, send_Buffer, 1, QUIC_SEND_FLAG_ALLOW_0_RTT, send_Buffer))) {
                sample_print("StreamSend failed, 0x%x!\n", status);
                free(send_buffer_raw);
      }
} break;

Expected behavior

can send data in stream_callback function on server-side

Actual outcome

none

Additional details

No response

lauix avatar Feb 21 '24 11:02 lauix

Expected Behavior

can send data in stream_callback function on server-side

You absolutely can send in any callback. I suggest you grab logs to diagnose what's going on here. Please see https://github.com/microsoft/msquic/blob/main/docs/Diagnostics.md#trace-collection for more details.

nibanks avatar Feb 21 '24 14:02 nibanks

I am also facing the same issue, is there any setting on the receiver which allows the response to be received inline when the data is sent in the stream_callback function on the server-side. However, I notice when I put a lot of data through a loop by sending multiple streamsend calls in the stream_callback function on the server-side, the data is received immediately back on the client.

JyothiAswath avatar Jul 24 '24 06:07 JyothiAswath

is there any setting on the receiver which allows the response to be received inline when the data is sent in the stream_callback function on the server-side

'inline' to what? The peer's send thread/call? Each connection is separate and not necessarily processed on the same thread.

nibanks avatar Jul 24 '24 12:07 nibanks

Yes, The peer( Server) is sending the RESP via MsQuic->StreamSend to the client during the event QUIC_STREAM_EVENT_RECEIVE within ServerStreamCallback. Whereas in the client, the event QUIC_STREAM_EVENT_RECEIVE within ClientStreamCallback is not triggered, hence the RESP is not received.

However, I modified the code to send the RESP from Server within the ServerStreamCallback in a loop about 1000 times, I could see QUIC_STREAM_EVENT_RECEIVE event triggerd twice in the ClientStreamCallback.

JyothiAswath avatar Jul 24 '24 13:07 JyothiAswath

You'll need to grab logs to diagnose further.

nibanks avatar Jul 24 '24 15:07 nibanks

After enabling the logs, here is my observation. When the RESP is not reaching the ClientStreamCallback , I see that QUIC_STREAM_EVENT_IDEAL_SEND_BUFFER_SIZE event is triggered. When the RESP is reaching the ClientStreamCallback, the expected event ( QUIC_STREAM_EVENT_RECEIVE ) is triggered and not the QUIC_STREAM_EVENT_IDEAL_SEND_BUFFER_SIZE

JyothiAswath avatar Jul 25 '24 09:07 JyothiAswath

is it normal that QUIC_STREAM_EVENT_RECEIVE is not triggered when QUIC_STREAM_EVENT_IDEAL_SEND_BUFFER_SIZE is not triggered? How are we suppose to handle in such a scenario.

JyothiAswath avatar Jul 29 '24 13:07 JyothiAswath

These two events are independent. QUIC_STREAM_EVENT_IDEAL_SEND_BUFFER_SIZE is about how much you should keep queued on the send side to have the best throughput. QUIC_STREAM_EVENT_RECEIVE is when you receive information on a stream.

In general, if you are calling StreamSend on one side, but not getting the QUIC_STREAM_EVENT_RECEIVE event on the other, it means the data you tried to send is getting blocked, likely on flow control. So either you haven't configuring the receiver to allow enough streams, or your receiver isn't draining the previous data it has.

nibanks avatar Jul 29 '24 13:07 nibanks