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

server-client ping-pong: Server should timeout #21

Closed
LeeTibbert opened this issue Sep 4, 2022 · 4 comments · Fixed by #31
Closed

server-client ping-pong: Server should timeout #21

LeeTibbert opened this issue Sep 4, 2022 · 4 comments · Fixed by #31

Comments

@LeeTibbert
Copy link
Collaborator

Presenting problem

For simplicity, I will phrase this in terms of the TcpSuite server-client ping-pong test,
but the problem is general to at least that Suite. I will also talk about accept() but
the fix is probably has to do with the socket_fd used for listen().

The issue is that sometimes one wants a server to sit and accept() connections for
the lifetime of the program. Other times, often if a human is waiting at the other
end, one wants to wait only a specified period and then timeout, perhaps to
do something about the lack of connection.

Currently, when there is some failure on the client path, ping-pong server hangs until it is
interrupted by user action (^C). Not good for an automated test.

If it is a culturally appropriate idiom, the server accept() ought to timeout.

Discussion

The crude hammer of alarm() can be mentioned and skipped over.

Linux has a concept of timerfds. I have not done it, but from
reading, these can be registered with epoll and used as one
of the events it monitors.

The may be some complexity. Somebody may need to
epoll on the listen_fd and the timer_fd. If the listen_fd
reports an suitable event, the C accept() is called.
I have not traced the epoll.scala accept call to look
at implementation. I first need to understand
the cultural milieu.

@armanbilge
Copy link
Owner

Note that in the TcpSuite, which uses cats.effect.IO, you can timeout any IO action simply by adding .timeout(...) to it.

https://typelevel.org/cats-effect/api/3.x/cats/effect/IO.html#timeout[A2%3E:A](duration:scala.concurrent.duration.FiniteDuration):cats.effect.IO[A2]

@LeeTibbert
Copy link
Collaborator Author

Thank you. I will look at that URL, learn some cats, and try in my experimental program.

Of course, now I have gone and hacked around what was causing the hang.

This Issue will serve as a reminder that I need to create a PR after I understand & get it working.

Rapid turn around progress.

@LeeTibbert
Copy link
Collaborator Author

I spent time tracing this one out. I feel like a hobo trying to catch a fast train, but I
will get there... I understand the Resource concept, and that I have one (serverCh).
Now I just need to access the IO part of that and set the timeout in a way that
the results can be passed further down the chain.

I have the timeout code executing several places without either harm or benefit,
so I have that part down. The cats doc gave a Scala FiniteDuration as the argument,
which meant that I had to introduce, in my scratch work, a scala import. It was the
first one, and I am always reluctant to introduce such. Too much time spent
working in javalib.

More next sprint (or the one thereafter).

@armanbilge
Copy link
Owner

Thank you for posting the reproducer in #29 (comment).

The problem is that accept as-written is uncancelable, which means it will not resolve until it either errors or accepts a connection. I think this can be fixed.

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

Successfully merging a pull request may close this issue.

2 participants