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
When subscribing to a second channel (in the same process) the second subscribe takes between 0 and whatever the ping value in seconds is set.
If a message is sent to that channel before the subscribe is successful, the message will not be received by the subscribed client, but the subscribe will finish when the message is sent.
This is most likely caused by the use of threads, sleep calls, blocking loops and I/O in this script, as well as running a threaded server and EventMachine in the same process. If I put the server in its own file and run it as a separate process, and write the client code to use EventMachine APIs for timers, everything works as expected:
require"bundler"require"bundler/setup"require"rack/handler/puma"require"net/http"Bundler.requireserver_timeout=30
$web_socket_url ="http://0.0.0.0:9393/faye"# Faye.logger = Logger.new(STDOUT)EM.run{client_timeout=server_timeout + 1client=Faye::Client.new($web_socket_url,timeout: client_timeout)defdo_sub(client,i)puts"Subscribing to channel #{i}"start_time=Time.now.to_fsub=client.subscribe("/channel/#{i}").with_channeldo |channel,message|
p["Got message on channel #{i}",channel,message]endsub.callbackdoduration=Time.now.to_f - start_timeputs"Channel #{i} subscribed in #{duration} seconds"endenddefsend_message(i)payload={channel: "/channel/#{i}",data: {foo: "bar"},}p[:send,payload]uri=URI.parse($web_socket_url)Net::HTTP.post_form(uri,message: JSON.dump(payload))enddo_sub(client,1)EM.add_timer(3)dodo_sub(client,2)EM.add_timer(3){send_message(2)}end}
When subscribing to a second channel (in the same process) the second subscribe takes between 0 and whatever the ping value in seconds is set.
If a message is sent to that channel before the subscribe is successful, the message will not be received by the subscribed client, but the subscribe will finish when the message is sent.
I have created this repository https://github.com/Karazum/faye_subscribe_test
To test this issue. The faye_server.rb script contains 3 tests.
1st test:
2nd test:
3rd test:
To conclude:
The text was updated successfully, but these errors were encountered: