Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection.activate_stream RuntimeError: can't add a new key into hash during iteration #123

Closed
tboyko opened this issue Mar 27, 2018 · 13 comments

Comments

@tboyko
Copy link

tboyko commented Mar 27, 2018

We're experiencing a very intermittent error using http-2 by way of net-http2 by way of Apnotic

E, [2018-03-27T03:50:05.485152 #657] ERROR -- : Actor crashed!
RuntimeError: can't add a new key into hash during iteration
	/var/www/[removed]/shared/bundle/ruby/2.5.0/gems/http-2-0.8.4/lib/http/2/connection.rb:669:in `activate_stream'
	/var/www/[removed]/shared/bundle/ruby/2.5.0/gems/http-2-0.8.4/lib/http/2/connection.rb:109:in `new_stream'
	/var/www/[removed]/shared/bundle/ruby/2.5.0/gems/net-http2-0.16.0/lib/net-http2/client.rb:86:in `new_stream'
	/var/www/[removed]/shared/bundle/ruby/2.5.0/gems/net-http2-0.16.0/lib/net-http2/client.rb:93:in `new_monitored_stream_for'
	/var/www/[removed]/shared/bundle/ruby/2.5.0/gems/net-http2-0.16.0/lib/net-http2/client.rb:40:in `call_async'
	/var/www/[removed]/shared/bundle/ruby/2.5.0/gems/apnotic-1.3.0/lib/apnotic/connection.rb:85:in `delayed_push_async'
	/var/www/[removed]/shared/bundle/ruby/2.5.0/gems/apnotic-1.3.0/lib/apnotic/connection.rb:49:in `push_async'
	/var/www/[removed]/releases/20170327013745/lib/[removed]/connection.rb:98:in `send_notification'
	/var/www/[removed]/shared/bundle/ruby/2.5.0/gems/celluloid-0.17.3/lib/celluloid/calls.rb:28:in `public_send'
	/var/www/[removed]/shared/bundle/ruby/2.5.0/gems/celluloid-0.17.3/lib/celluloid/calls.rb:28:in `dispatch'
	/var/www/[removed]/shared/bundle/ruby/2.5.0/gems/celluloid-0.17.3/lib/celluloid/call/async.rb:7:in `dispatch'
	/var/www/[removed]/shared/bundle/ruby/2.5.0/gems/celluloid-0.17.3/lib/celluloid/cell.rb:50:in `block in dispatch'
	/var/www/[removed]/shared/bundle/ruby/2.5.0/gems/celluloid-0.17.3/lib/celluloid/cell.rb:76:in `block in task'
	/var/www/[removed]/shared/bundle/ruby/2.5.0/gems/celluloid-0.17.3/lib/celluloid/actor.rb:337:in `block (2 levels) in task'
	/var/www/[removed]/shared/bundle/ruby/2.5.0/gems/celluloid-0.17.3/lib/celluloid/task.rb:97:in `exclusive'
	/var/www/[removed]/shared/bundle/ruby/2.5.0/gems/celluloid-0.17.3/lib/celluloid.rb:421:in `exclusive'
	/var/www/[removed]/shared/bundle/ruby/2.5.0/gems/celluloid-0.17.3/lib/celluloid/actor.rb:337:in `block in task'
	/var/www/[removed]/shared/bundle/ruby/2.5.0/gems/celluloid-0.17.3/lib/celluloid/task.rb:44:in `block in initialize'
	/var/www/[removed]/shared/bundle/ruby/2.5.0/gems/celluloid-0.17.3/lib/celluloid/task/fibered.rb:14:in `block in create'

The issue at connection.rb:669 is not readily apparent to me. Perhaps this is a concurrency problem with some other part of the library iterating over this array at the same time?

@igrigorik
Copy link
Owner

Hmm.. @ostinelli any insights on what might be the issue here?

@ostinelli
Copy link
Collaborator

ostinelli commented May 2, 2018

Unfortunately not, though it does seem an issue related to Celluloid and concurrency used with Http2 / NetHttp2 / Apnotic. Never seen this one myself, though I have not used any of this together with Celluloid.

@igrigorik
Copy link
Owner

@tboyko I'd suggest routing this to Celluloid tracker.. Without a repro case, it's hard to provide any meaningful feedback here.

@ioquatix
Copy link
Collaborator

Are you sharing state between actors? By default they run on their own threads IIRC. I don't think http-2 is thread safe (which is probably to be expected).

@tboyko
Copy link
Author

tboyko commented Jul 1, 2018 via email

@ioquatix
Copy link
Collaborator

ioquatix commented Jul 1, 2018

Is it possible you are passing something between actors as an argument?

@tboyko
Copy link
Author

tboyko commented Jul 1, 2018 via email

@ioquatix
Copy link
Collaborator

ioquatix commented Jul 1, 2018

As long as the ownership is passed to the other actor it should be okay. That means once you dispatch the request, e.g. actor.async.make_request(body, notification), you don't touch body or notification again.

How does the read/write loop work?

Because if you are not careful, it might be possible you have multiple fibers entering into the http-2 code and that could be causing problems. Can you point me at the code where you do reading and writing from the network?

@tboyko
Copy link
Author

tboyko commented Jul 1, 2018 via email

@ioquatix
Copy link
Collaborator

ioquatix commented Jul 1, 2018

Fair enough.

My understanding that celluloid is no longer being maintained. My last experience with celluloid-io was that it was buggy. So it may well not be an issue with apnotic/http-2.

If you are looking for a solution, I'm working on async-http which might provide the foundation you require for further development. Let me know if you are interested. https://github.com/socketry/async-http

@ioquatix ioquatix closed this as completed Jul 1, 2018
@ioquatix
Copy link
Collaborator

ioquatix commented Jul 1, 2018

Also I see it's quite an old version of http-2. Perhaps updating that would be worth a try.

@ioquatix
Copy link
Collaborator

ioquatix commented Jul 1, 2018

Just for interest, I took a look where it was possible that streams was being enumerated:

when :local
@local_window = @local_window - @local_window_limit + v
@streams.each do |_id, stream|
stream.emit(:local_window, stream.local_window - @local_window_limit + v)
end
@local_window_limit = v
when :remote
@remote_window = @remote_window - @remote_window_limit + v
@streams.each do |_id, stream|
# Event name is :window, not :remote_window
stream.emit(:window, stream.remote_window - @remote_window_limit + v)
end
@remote_window_limit = v
end

So it seems odd that it would be in that block at the same time as trying to create a new stream... I'd need to see the celluloid actor code.

@tboyko
Copy link
Author

tboyko commented Jul 2, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants