enwi / dartzmq

A simple dart zeromq implementation/wrapper around the libzmq C++ library
https://pub.dev/documentation/dartzmq/latest/
MIT License
26 stars 17 forks source link

EINTR: The operation was interrupted #36

Open Zqiang12345 opened 5 months ago

Zqiang12345 commented 5 months ago

On Android, I use socket.send(result); socket.recv();
An error will be reported E/flutter (18544): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: ZeroMQException(4): EINTR: The operation was interrupted E/flutter (18544): #0 _checkErrorCode (package:dartzmq/src/exception.dart:56:5) E/flutter (18544): #1 _checkReturnCode (package:dartzmq/src/exception.dart:49:5) E/flutter (18544): #2 ZSyncSocket.recv (package:dartzmq/src/socket.dart:406:9) E/flutter (18544): #3 _FirmwareBodyWidgetState._sendNextMessage (package:healthy_voice/ui/config/firmware_version.dart:179:18)

on ios socket.recv(); Cannot set timeout

when i use socket.messages.listen((message) { print('Received: $message'); // _sendNextMessage(); });

An error will be reported E/flutter (18544): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: ZeroMQException(156384763): Operation cannot be accomplished in current state E/flutter (18544): #0 _checkErrorCode (package:dartzmq/src/exception.dart:56:5) E/flutter (18544): #1 _checkReturnCode (package:dartzmq/src/exception.dart:49:5) E/flutter (18544): #2 ZContext._poll (package:dartzmq/src/zeromq.dart:109:9) E/flutter (18544): #3 ZContext._startPolling. (package:dartzmq/src/zeromq.dart:68:70) E/flutter (18544): #4 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19) E/flutter (18544): #5 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5) E/flutter (18544): #6 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

enwi commented 5 months ago

Could it be that you are sending a null message? According to this EINTR is thrown for a null message.

Zqiang12345 commented 5 months ago

Could it be that you are sending a null message? According to this EINTR is thrown for a null message.

I'm going to abandon the synchronous method if I have data, but I get an error when I use asynchronous listening

E/flutter (18544): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: ZeroMQException(156384763): Operation cannot be accomplished in current state E/flutter (18544): #0 _checkErrorCode (package:dartzmq/src/exception.dart:56:5) E/flutter (18544): https://github.com/enwi/dartzmq/issues/1 _checkReturnCode (package:dartzmq/src/exception.dart:49:5) E/flutter (18544): https://github.com/enwi/dartzmq/issues/2 ZContext._poll (package:dartzmq/src/zeromq.dart:109:9) E/flutter (18544): https://github.com/enwi/dartzmq/issues/3 ZContext._startPolling. (package:dartzmq/src/zeromq.dart:68:70) E/flutter (18544): https://github.com/enwi/dartzmq/issues/4 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19) E/flutter (18544): https://github.com/enwi/dartzmq/issues/5 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5) E/flutter (18544): https://github.com/enwi/dartzmq/pull/6 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

Zqiang12345 commented 5 months ago

I'm using the req/rep mode

enwi commented 5 months ago

Please use a dealer socket instead of the req socket when using the async socket

Zqiang12345 commented 5 months ago

Please use a dealer socket instead of the req socket when using the async socket

When I used the sync mode, ios worked properly and Android reported an error as I mentioned above, and I couldn't set the timeout period, which would cause the program to get stuck

Zqiang12345 commented 5 months ago

Could it be that you are sending a null message? According to this EINTR is thrown for a null message.

We have data. ios is working fine

Zqiang12345 commented 5 months ago
                            socket.send(result);
                            Future.delayed(Duration(milliseconds: 1000),(){
                              final message = socket.recv();
                              print("getMessage $message");
                            });

I don't seem to have real synchronization on Android. I need to delay the recv() method to receive the data. If I call recv() directly, I get an error "EINTR: The operation was interrupted ", which is probably what you mean by null date because I'm not receiving data

enwi commented 5 months ago

I think we must ignore the EINTR like it is done for the async sockets https://github.com/enwi/dartzmq/blob/70030a9f2dbf329aaebbbcbe67134baa14a6b175/lib/src/zeromq.dart#L109

Can you try adding that ignore?

Zqiang12345 commented 5 months ago

I think we must ignore the EINTR like it is done for the async sockets

https://github.com/enwi/dartzmq/blob/70030a9f2dbf329aaebbbcbe67134baa14a6b175/lib/src/zeromq.dart#L109

Can you try adding that ignore?

I am very sorry for not replying to your message in time. I used ^1.0.0-dev.17 with _checkReturnCode(rc, ignore: [EAGAIN, EINTR]); But this error still occurs. Have you not repeated this error ?

enwi commented 5 months ago

I haven't tested it myself yet