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

Connection closed despite successful command #24

Closed
auroraanna opened this issue Apr 4, 2024 · 7 comments
Closed

Connection closed despite successful command #24

auroraanna opened this issue Apr 4, 2024 · 7 comments

Comments

@auroraanna
Copy link

I can successfully create a connection with mpd and ask for the protocol version e.g. but as soon as I send a command the connection is closed. Due to ConnectionClosed being an error in the Result from running a command, if I query the status e.g., i won't actually get it. However, the commands have an effect on the mpd server: stop works and I can see status data being sent back over TCP.

By running tcpdump I can see that to the end of a TCP connection, this library sends an empty message over TCP, which is followed by an empty TCP message by mpd and again, and empty TCP message by this library:


song: 0
songid: 186
OK

23:10:02.763061 IP localhost.35920 > localhost.mshvlm: Flags [F.], seq 68, ack 173, win 260, options [nop,nop,TS val 1105770442 ecr 1105770441], length 0
E..4.<@.@.F..........P...#c._+.`.....(.....
A...A...
23:10:02.763212 IP localhost.mshvlm > localhost.35920: Flags [F.], seq 173, ack 69, win 260, options [nop,nop,TS val 1105770442 ecr 1105770442], length 0
E..4:.@.@..............P_+.`.#c......(.....
A...A...
23:10:02.763275 IP localhost.35920 > localhost.mshvlm: Flags [.], ack 174, win 260, options [nop,nop,TS val 1105770442 ecr 1105770442], length 0
E..4.=@.@.F..........P...#c._+.a.....(.....
A...A...

Afaik sending an empty message means that you are shutting down the TCP connection.

@elomatreb
Copy link
Owner

elomatreb commented Apr 7, 2024

Can you try getting debug logs while this is happening? (feel free to ask how if necessary)

@auroraanna
Copy link
Author

adding RUST_LOG=debug didn't change the output but other than last time i tried, the unwrapping the command's Result doesn't error but it does in another function. investigating this…

@auroraanna
Copy link
Author

I store the Client inside of a struct. While the first function works perfectly fine, at the start of the second function, the Client is already disconnected. The disconnect doesn't seem to just happen when a command is sent.

Both are functions are inside and impl and the Client is stored in the corresponding struct.

Does the client go out of scope and then disconnect or something? Also in the first function, the struct is borrowed as mutable so you can use .as_mut() on the Client and the unwrap() (Option). However, in the other function the struct is not borrowed at mutable and has to match the Option. Anna is wondering if the is part of the problem.

@auroraanna
Copy link
Author

source code here

@elomatreb
Copy link
Owner

adding RUST_LOG=debug didn't change the output

You also need to install a subscriber, e.g. from the tracing_subscriber crate (as simple as tracing_subscriber::fmt().init(); at the top of the main function).

But I think I know what is happening: The runtime created here is dropped implicitly at the end of the scope, which in turn breaks the TCP connection used internally by this library. Keeping the runtime around as long as the Client exists might already be sufficient to fix this behavior.

@elomatreb
Copy link
Owner

Does this still occur for you?

@elomatreb
Copy link
Owner

I'll close this for now, feel free to reopen if necessary.

@elomatreb elomatreb closed this as not planned Won't fix, can't repro, duplicate, stale Apr 18, 2024
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