Skip to content

Handle descriptor in non-blocking mode properly.#551

Merged
jnovy merged 1 commit intocontainers:mainfrom
jnovy:pollfix
Apr 15, 2025
Merged

Handle descriptor in non-blocking mode properly.#551
jnovy merged 1 commit intocontainers:mainfrom
jnovy:pollfix

Conversation

@jnovy
Copy link
Collaborator

@jnovy jnovy commented Mar 24, 2025

Resolves: #490

@jnovy jnovy requested a review from haircommander March 24, 2025 17:51
@haircommander
Copy link
Collaborator

LGTM, @giuseppe would you PTAL

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

I've left some comments.

Would it still work if we include only these chunks?

		if (errno == EAGAIN || errno == EWOULDBLOCK) {
			// Non-blocking mode - no data available, return gracefully
			return false;

and:

		if (!written)
			return false;

src/ctr_stdio.c Outdated

if (poll_ret == 0) {
// No data available, return gracefully
return true;
Copy link
Member

Choose a reason for hiding this comment

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

if we keep looping in drain_stdio I don't see the advantage in using a non blocking socket. We need to return false here and do not attempt to read again or am I missing something?

} else if (num_read < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
// Non-blocking mode - no data available, return gracefully
return true;
Copy link
Member

Choose a reason for hiding this comment

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

same here

src/ctr_stdio.c Outdated

// Use poll to check if data is available before reading
struct pollfd pfd = {.fd = fd, .events = POLLIN};
int poll_ret = poll(&pfd, 1, 500); // 500ms timeout
Copy link
Member

Choose a reason for hiding this comment

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

this will slow down conmon cleanup if there is no data available and I don't see why we need to poll the fd? If we end up here, there was an event of the file descriptor or we are draining the fd until there is data, but in this case the fd is in non-blocking mode. Do we get spurious events that cause read_stdio to be called without any data avaiable?

@jnovy
Copy link
Collaborator Author

jnovy commented Apr 14, 2025

Ok, let's keep it simple - I will remove the polling - it adds more complexity and potentially could slow things down (+the 500ms magic constant).

Resolves: containers#490

Signed-off-by: Jindrich Novy <jnovy@redhat.com>
Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

LGTM

@jnovy jnovy merged commit 2e66c1c into containers:main Apr 15, 2025
28 of 29 checks passed
@jnovy jnovy deleted the pollfix branch April 16, 2025 06:46
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 this pull request may close these issues.

conmon c82ee1934e559bd5868f <nwarn>: stdio_input read failed Resource temporarily unavailab

3 participants