-
Type: Bug
-
Resolution: Done
-
Priority: Critical - P2
-
Affects Version/s: 2.4.1
-
Component/s: None
-
None
In our application we sometimes get the error, here's the top part of the stack trace:
mongo (2.4.1) lib/mongo/socket.rb:180:in `select' mongo (2.4.1) lib/mongo/socket.rb:180:in `rescue in read_from_socket' mongo (2.4.1) lib/mongo/socket.rb:174:in `read_from_socket' mongo (2.4.1) lib/mongo/socket.rb:123:in `block in read' mongo (2.4.1) lib/mongo/socket.rb:199:in `handle_errors' mongo (2.4.1) lib/mongo/socket.rb:122:in `read' mongo (2.4.1) lib/mongo/protocol/message.rb:131:in `deserialize' mongo (2.4.1) lib/mongo/server/connectable.rb:114:in `block in read' mongo (2.4.1) lib/mongo/server/connectable.rb:97:in `ensure_connected' mongo (2.4.1) lib/mongo/server/connectable.rb:113:in `read' mongo (2.4.1) lib/mongo/server/connection.rb:163:in `deliver' mongo (2.4.1) lib/mongo/server/connection.rb:108:in `block in dispatch' mongo (2.4.1) lib/mongo/monitoring/publishable.rb:47:in `publish_command' mongo (2.4.1) lib/mongo/server/connection.rb:107:in `dispatch' mongo (2.4.1) lib/mongo/operation/executable.rb:37:in `block in execute' mongo (2.4.1) lib/mongo/server/connection_pool.rb:107:in `with_connection' mongo (2.4.1) lib/mongo/server.rb:242:in `with_connection' mongo (2.4.1) lib/mongo/operation/executable.rb:35:in `execute' mongo (2.4.1) lib/mongo/cursor.rb:188:in `block in get_more' mongo (2.4.1) lib/mongo/retryable.rb:51:in `read_with_retry' mongo (2.4.1) lib/mongo/cursor.rb:187:in `get_more' mongo (2.4.1) lib/mongo/cursor.rb:113:in `each' mongo (2.4.1) lib/mongo/collection/view/iterable.rb:44:in `each' mongoid (5.2.0) lib/mongoid/query_cache.rb:221:in `each' mongoid (5.2.0) lib/mongoid/contextual/mongo.rb:129:in `each' mongoid (5.2.0) lib/mongoid/contextual.rb:20:in `each'
Unfortunately I'm not able to create a reproducible case but it looks like the problem is line lib/mongo/socket.rb:179. There select_timeout may be negative if more than timeout has passed since the start of read_from_socket. Passing a negative value to Kernel::select is what causes the issue. If the value is negative the exception should be raised directly.