rkbalgi / iso8583_rs

ISO8583 library written in Rust
Apache License 2.0
11 stars 3 forks source link

03:17:06 [ERROR] client socket_err: 127.0.0.1:48304 failed to fill whole buffer #10

Closed chmoder closed 4 years ago

chmoder commented 4 years ago

Hi there, I was trying out your crate today and noticed this error: 03:17:06 [ERROR] client socket_err: 127.0.0.1:48304 failed to fill whole buffer.

I spent some time trying to fix it, and I am new to rust and ISO 8583, so maybe you can help me solve the problem and learn something along the way.

When I run test_send_recv_iso_1100 the server emits this error, but it may be misleading. server.mli.parse Throws an IsoError with std::io::error::ErrorKind::UnexpectedEof here.

It may be because in_buff is being processed twice for some reason? I can't quite tell.

rkbalgi commented 4 years ago

Hi Thomas, I'm new to Rust too :-) and so yes, we can all learn something.

The error is definitely misleading and I'l try to fix it. What the error is saying really is "the client closed the connection". You can see the same on my github page too :-) here- scroll to the very end

15:54:47 [DEBUG] (3) iso8583_rs::iso8583::server: request processing time = 9 millis
15:54:47 [ERROR] client socket_err: 127.0.0.1:56307 failed to fill whole buffer

(So far I have been able to make out that in rust if a socket read returns 0 means that the client has closed the connection. In other languages you might get a -1 or a SocketClosedException)

BTW, when you run the server (main.rs) and then the _test_send_recv_iso1100, do you see the server processing the request and the test side receiving the response?

rkbalgi commented 4 years ago

I've made some changes on the master branch to report a slightly meaningful message -

17:48:28 [DEBUG] (3) iso8583_rs::iso8583::server: request processing time = 2 millis
17:48:28 [ERROR] client socket_err: 127.0.0.1:50920 connection closed. cause: UnexpectedEof
chmoder commented 4 years ago

Thanks,

I'll take a look at this later as well. I can see that when the client closes the connection https://github.com/rkbalgi/iso8583_rs/blob/0bc7ede98c002f2acc7dfc38394c1a45bd221b8b/src/iso8583/mli.rs#L36 gets some non-iso value. Probably 0 like you were saying.

chmoder commented 4 years ago

Hi Thomas, I'm new to Rust too :-) and so yes, we can all learn something.

The error is definitely misleading and I'l try to fix it. What the error is saying really is "the client closed the connection". You can see the same on my github page too :-) here- scroll to the very end

15:54:47 [DEBUG] (3) iso8583_rs::iso8583::server: request processing time = 9 millis
15:54:47 [ERROR] client socket_err: 127.0.0.1:56307 failed to fill whole buffer

(So far I have been able to make out that in rust if a socket read returns 0 means that the client has closed the connection. In other languages you might get a -1 or a SocketClosedException)

BTW, when you run the server (main.rs) and then the _test_send_recv_iso1100, do you see the server processing the request and the test side receiving the response?

Yes, I see the test client receive a response, then it's like it sends another response back to the server.

rkbalgi commented 4 years ago

The server prints the request it received from the client and also the response that it sent, may be that is where the confusion is? (The client only prints out the response)

chmoder commented 4 years ago

The more I learn about Rust TCP sockets the more I think it's simply a closed connection - which it appears sends a 0.

If we can find a way to check that the next byte is not 0 before passing it to mli.parse, we may be able to keep the connection setup this way. Basically https://github.com/rkbalgi/iso8583_rs/blob/d7e8e4256e4e6923bb1c451db38449645355e772/src/iso8583/mli.rs#L47 tries to read the buffer (as it should) but after the client closes it's connection it has nothing to read, because the client sent EOF.

rkbalgi commented 4 years ago

Well, the client could disconnect at any point in time, while reading the MLI or the actual data. You could try to do a check before passing it to mli.parse, perhaps this may be useful? https://doc.rust-lang.org/beta/std/net/struct.TcpStream.html#method.peek

chmoder commented 4 years ago

Hi Raghavendra,

I have a solution in a separate local branch to handle the situation when a client closes a connection. Is get a permission denied error when trying to push my local branch to this repo. I would like to create a PR here, however, if that is not ideal for you, please let me know if and how you would like to see the solution.

rkbalgi commented 4 years ago

Hi @chmoder, You may have to fork the repo and then open a PR.

chmoder commented 4 years ago

Hi @chmoder, You may have to fork the repo and then open a PR.

Silly me. I don't know what was going on in my head yesterday. PR opened, thank you for the fun!