-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Unable to catch error "SocketException: OS Error: Broken pipe" #47538
Comments
Actually, I believe this is working as intended. The callback that you are passing to periodic is async. It's executing (repeatedly) after main is complete. I.e., it's not actually running under the try-catch in main. |
I think that is it catch inside timer that should catch exception. Timer acts like while loop. Future main(List<String> args) async {
try {
Connection con = await Connection.connect('127.0.0.1', 3333);
int tick = 0;
while(true){
try {
final String s = "ping ${tick}";
print("send $s");
var ret = await con.send_to_echo(s);
print("recv $ret");
} catch (e,s) {
print('loop:$e $s');
}
tick += 1;
await Future.delayed(Duration(milliseconds: 1000));
}
} catch (e,s) {
print("main:$e $s");
}
print("done");
} |
I modified the above code as follows
and I do see the message from the catch statement 'loop:closed stream', and the following 'done' being printed. |
Thank you for your help. Additionally can you modify your program to delay a little before main terminates and report on result. For example: print("done start");
await Future.delayed(Duration(milliseconds: 1000));
print("done done");
}
// end of file We expect to get "done done" on output. Reason is that I do catch first exception that is raised by |
I made the modifications suggested by you as follows
and here is the output when I run it
|
Thank you @a-siva you this solve an issue. Is this expected behavior? It seems that one needs to close connection "quick enough" to stop propagating 2nd exception. |
I believe the exception mechanism seems to work on the |
if the send_to_echo method is modified to only send data and not try to read anything as follows
and run the modified 'main' method I have above then it does result in the unhandled exception We seem to have an issue propogating exceptions correctly when a write is done to a socket that has been disconnected. |
The reason I was getting unhandled SocketExceptions in the above code was because I did not register a listener for the socket stream. I modified the code as follows and things work just fine
Output from client running the above code
|
Things appear to work as expected, I am closing this issue, if you think there are more issues please do not hesitate to reopen it. |
I think that current approach is similar to initial workaround and that issue remains. One need to close socket to stop propagating exceptions. It is also not clear how to catch generated exception. For example if we comment out |
i find that we have to call before this i couldn't even get the stacktrace of where it was raised even if i called |
We send data from dart acting as client to tcp echo server (not included here). At some point we kill this echo server.
It happens that once this happens we can not catch exception on dart that acts as client.
Application terminates with Unhandled exception: error.
And here is last part of output, where app terminates after server is killed.
Dart version running in container "docker.io/google/dart:2.15-dev" on linux
The text was updated successfully, but these errors were encountered: