meetecho / janus-gateway

Janus WebRTC Server
https://janus.conf.meetecho.com
GNU General Public License v3.0
8.12k stars 2.46k forks source link

[1.1.2] janus transports http bug #3178

Closed fengyj2022 closed 1 year ago

fengyj2022 commented 1 year ago

janus transports http bug

  1. // Start creating the service instance

MHD_start_daemon

  1. Suspend the new connection and wait for a reply. Test if a response is created

/ Suspend the connection /

MHD_suspend_connection(msg-> connection);

  1. Create a response object when a new request is received, adding header Settings

1) struct MHD_Response *response = MHD_create_response_from_callback(MHD_SIZE_UNKNOWN,

500, &janus_http_response_callback, msg, NULL);

// The callback to get the response data and copy the body of the callback into the pyload of the response

janus_http_response_callback

/ add response header /

2).MHD_add_response_header (response, "Content-Type", "application/json");

/ add cors header /

3).janus_http_add_cors_headers (msg, response);

  1. // Queues the response for delivery to the client as soon as possible, in which case the header set in step 3 is placed in the connection object

ret = MHD_queue_response(msg-> connection, MHD_HTTP_OK, response);

  1. // Destroy the response object and associated resources (decrement the reference count)

MHD_destroy_response(response);

The callback is received to process send_messages

Assign the received response_text to the response's pyload.

  1. / resume the connection / Resume the connection and send the data

MHD_resume_connection(msg-> connection);

View the microhttpd library source At the end of step 4, the connection-> state is set from MHD_CONNECTION_HEADERS_PROCESSED to MHD_CONNECTION_FOOTERS_RECEIVED, In MHD_CONNECTION_FOOTERS_RECEIVED the thread copies the header into the header of the sent packet

So at step 6, there is no way to change the header information by re-executing steps 3 and 6. In step 6, the header is updated again; calling MHD_queue_response causes a deadlock.

Please help to solve the bug

The operation I want:modify the response packet header upon receipt of janus_http_send_message

fengyj2022 commented 1 year ago

@lminiero

lminiero commented 1 year ago

From your description, it looks like this is a bug you're encountering because you're trying to modify the code of the HTTP plugin for something you need. As such, I don't think it can be considered a bug. I'd only consider it a bug if specific interactions on the HTTP side can lead to the deadlock you described, which from what I understood is not the case.

fengyj2022 commented 1 year ago

@lminiero I found that the microhttpd library does not support modifying the header after receiving a callback. Do you have such a problem? Is there a solution?

lminiero commented 1 year ago

I don't know, but that's out of scope here. Please ask on their mailing list.

fengyj2022 commented 1 year ago

@lminiero Yes, I have built a bugtracker. If you have similar problems, please help me .https://bugs.gnunet.org/view.php?id=7757

fengyj2022 commented 1 year ago

How did you implement whep and whip on janus' http c voice library?

lminiero commented 1 year ago

I didn't, I implemented WHIP and WHEP as thin layers in front of Janus, not inside Janus itself: https://github.com/meetecho/simple-whip-server https://github.com/meetecho/simple-whep-server