Trouble with fibers

#1
Will be listening on 8080
#initialize - false
#call - false
"Hello world!"
Will be listening on 8080
#initialize - true
#call - false
"Hello world!"

Is the output.

Notice how it says enabled is true in initialize but false in call. So it’s being initialized correctly, but when accessing the config ivar in another method it is wrong?

Could someone explain what’s going on/how to fix it? I wouldn’t be surprised if its just me not doing something correctly with the fibers in the method tho.

0 Likes

#2

If you turn the structs into classes and print @config.object_id you’ll notice it’s using the same config object in the call. I think what’s happening is that CLIENT is using keep-alive so the second request is still hitting the first server, which for some reason isn’t being properly closed. If you use two different HTTP::Clients it works fine.

1 Like

#3

Ooo good call!

It seems adding CLIENT.close in the ensure block fixes it as well. Since I will be using this for testing, would it be better to create a new client in do_with_config and pass that as a block arg, so that each block is using its own client instance?

EDIT: Thats what i went with.

0 Likes