Skip to content

- add connection timeout#569

Merged
Enet4 merged 6 commits intoEnet4:masterfrom
jmlaka:add_conn_timeout
Oct 12, 2024
Merged

- add connection timeout#569
Enet4 merged 6 commits intoEnet4:masterfrom
jmlaka:add_conn_timeout

Conversation

@jmlaka
Copy link
Copy Markdown
Contributor

@jmlaka jmlaka commented Oct 8, 2024

A TCP connection od a client connection will hang in case of an invalid address or network error.
This adds the option of a connection timeout, which is different from the already implemented read/write timeout on the TcpStream

Copy link
Copy Markdown
Owner

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, looks nice and simple! Please see the minor suggestions below and we should be able to merge afterwards!

@jmlaka
Copy link
Copy Markdown
Contributor Author

jmlaka commented Oct 9, 2024

@Enet4 would this work ?
Thanks

@Enet4 Enet4 added enhancement A-lib Area: library C-ul Crate: dicom-ul labels Oct 11, 2024
Copy link
Copy Markdown
Owner

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for committing to the PR so far. I have just one more concern and then we can merge.

let conn_result: Result<TcpStream> = if let Some(timeout) = connection_timeout {
let addresses = ae_address.to_socket_addrs().context(ToAddressSnafu)?;

let mut res: Result<TcpStream> = NoAddressSnafu {}.fail();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would appreciate it if you could avoid building this Result::Err every time, because this makes the function pay the cost of constructing a backtrace even when it is not used.

@jmlaka
Copy link
Copy Markdown
Contributor Author

jmlaka commented Oct 12, 2024

As I had to store all the connection errors up to an Ok result, I had to use a Vec.
When calling .context(ConnectSnafu), the Backtrace is generated only in the case of Result::Err but not in the case of Result::Ok. Is that right?

@jmlaka
Copy link
Copy Markdown
Contributor Author

jmlaka commented Oct 12, 2024

So this last one fails early by borrowing the addresses iterator and count() ing it.
Then I construct one os Error in the cheapest way possible (it will never be returned).
And avoid using a Vec ...

Copy link
Copy Markdown
Owner

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Thanks! 👍

@Enet4 Enet4 merged commit e2162f2 into Enet4:master Oct 12, 2024
@jmlaka
Copy link
Copy Markdown
Contributor Author

jmlaka commented Oct 12, 2024

@Enet4 please retract this pull request as the code does not work as intended I am sorry.
I will rewrite it and add a connection test.
Thank you

@Enet4
Copy link
Copy Markdown
Owner

Enet4 commented Oct 12, 2024

Hm, I'm away from a desktop computer, but if you write a pull request within the weekend I'll likely have a moment to try it out and merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-lib Area: library C-ul Crate: dicom-ul enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants