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

Stack overflow when reading data #127

Open
timk10 opened this issue May 4, 2018 · 2 comments
Open

Stack overflow when reading data #127

timk10 opened this issue May 4, 2018 · 2 comments

Comments

@timk10
Copy link
Contributor

timk10 commented May 4, 2018

We run into stack overflow error due to handleBody/handleHeader calling itself repeatedly (see stacktrace)

Socket error Stack Overflow #0 List.setRange (dart:core-patch/array.dart:31) #1 PacketConverter._readPacketIntoBuffer (package:plato_mongo_dart/src/network/packet_converter.dart:72:12) #2 PacketConverter.handleBody (package:plato_mongo_dart/src/network/packet_converter.dart:63:19) #3 PacketConverter.handleHeader (package:plato_mongo_dart/src/network/packet_converter.dart:37:7) #4 PacketConverter.handleBody (package:plato_mongo_dart/src/network/packet_converter.dart:48:7) #5 PacketConverter.handleHeader (package:plato_mongo_dart/src/network/packet_converter.dart:37:7) #6 PacketConverter.handleBody (package:plato_mongo_dart/src/network/packet_converter.dart:48:7) #7 PacketConverter.handleHeader (package:plato_mongo_dart/src/network/packet_converter.dart:37:7) #8 PacketConverter.handleBody (package:plato_mongo_dart/src/network/packet_converter.dart:48:7) #9 PacketConverter.handleHeader (package:plato_mongo_dart/src/network/packet_converter.dart:37:7) #10 PacketConverter.handleBody (package:plato_mongo_dart/src/network/packet_converter.dart:48:7) #11 PacketConverter.handleHeader (package:plato_mongo_dart/src/network/packet_converter.dart:37:7) #12 PacketConverter.handleBody (package:plato_mongo_dart/src/network/packet_converter.dart:48:7) #13 PacketConverter.handleHeader (package:plato_mongo_dart/src/network/packet_converter.dart:37:7) ... ... #14864 _StreamController.add (dart:async/stream_controller.dart:603) #14865 _Socket._onData (dart:io-patch/socket_patch.dart:1617) #14866 StackZoneSpecification._registerUnaryCallback.<anonymous closure>.<anonymous closure> (package:stack_trace/src/stack_zone_specification.dart) #14867 StackZoneSpecification._run (package:stack_trace/src/stack_zone_specification.dart) #14868 StackZoneSpecification._registerUnaryCallback.<anonymous closure> (package:stack_trace/src/stack_zone_specification.dart:107:14) #14869 _rootRunUnary (dart:async/zone.dart) #14870 _CustomZone.runUnaryGuarded (dart:async/zone.dart) #14871 _StreamController.add (dart:async/stream_controller.dart:603) #14872 new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1203) #14873 _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart) #14874 _startMicrotaskLoop (dart:async/schedule_microtask.dart) #14875 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart)

Upon reading the code it seems if there are more than 7400+ messages in a single packet (back of napkin calculation: based on the # of stacks, around 14864/2 ~ 7432 messages) then it would cause the 2 functions calling each other until stack overflow.

Seems there could be 2 scenarios

  1. If Mongo decides to send a packet with many messages.
  2. It's also possible that Dart batches all the messages into a single packet.

I'm not able to reproduce it locally, but I do see it happen quite often in production so I'm not able to nail down which of the above scenarios caused the issue.

Is there a reason why we choose to read the packets recursively?
Should we handle reading of the packets in iterative manner rather than recursive?

@timk10 timk10 changed the title Stack overflow when reading some data Stack overflow when reading data May 4, 2018
@Pacane
Copy link
Collaborator

Pacane commented May 4, 2018

Sorry, is this really a mongo_dart issue? I don't see any line in the stacktrace that belongs to mongo_dart?

@timk10
Copy link
Contributor Author

timk10 commented May 4, 2018

Sorry, we forked a version of it so that we could reconnect if there were socket error Change is here: (timk10@9070d7e).

However rest of the code is still the same.

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

2 participants