Uh oh!
There was an error while loading. Please reload this page.
feat: Possibility to immediately kill worker thread - #54
Conversation
keelerm84
commented
Apr 18, 2025
@Exterm1nate thank you for raising the issue and working on this contribution. I would prefer to not expose the thread as that's an implementation detail, and it enables a lot of misuse. I've updated the PR to add a Would this work for you? |
Exterm1nate
commented
Apr 18, 2025
This solution appears to work, but it has a noticeable disadvantage: tests will take longer if we wait for the last |
keelerm84
commented
Apr 21, 2025
I wouldn't expect this to take long at all. That method should early exit when it sees we have called close. This makes me think something else is preventing the thread from exiting immediately, like a hung IO reader. Do you have a small reproduction case I could reference to dig into this further? |
Exterm1nate
commented
May 5, 2025
This code emulates my test suite: RSpec.describe"stream processor"docontext"with stream"dosubject(:call_method)dostream# Wait for SSE client preparationssleep0.1endlet!(:obj){instance_double("object",success: nil,failure: nil)}let(:stream)dostream=SSE::Client.new("http://localhost:3000")stream.on_eventdo |event|
# Success logicobj.successendstream.on_errordo |e|
# Fail logicobj.failureendstreamendbeforedostub_request(:get,"http://localhost:3000").to_return({body: "event: created\ndata: my_data\n\n",headers: {"Content-Type"=>"text/event-stream"},})endafterdo# Uncomment one of:# stream.close# stream.close_and_waitend10.timesdo |i|
it"executes success callback [#{i}]"docall_methodexpect(obj).tohave_received(:success)endendendcontext"without stream"do10.timesdo |i|
it"does nothing [#{i}]"dosleep0.3expect(true).tobe(true)endendendendContext When using When using When using The performance difference between If you don't want to expose the thread (and I agree with it, it's an implementation detail that should be private) maybe we can add a method, that immediately stops the stream? Like |
Exterm1nate
commented
May 16, 2025
I added Review please. |
When stopping the client its thread continues working for some time. This is not a problem in production, but in tests it is. Webmock removes its stub after the test, while the thread is still working, so we sometimes receive such errors:
This PR adds a reader for thread, so it can be killed after the test example.