Skip to content

ftp functions can abort with EINTR #16800

Description

@bwoebi

Description

The underlying cause is poll(2) syscalls in the ext/ftp code (poll is one of those syscalls which cannot be resumed via SA_RESTART).
Short of guarding every single ftp operation, there's no way to cleanly resume ftp processing.
Especially given that the ext/ftp operations are sometimes big operations - like, I don't really have certainty on whether a transfer properly happened or not, I just know it was aborted.

my_send() and my_recv() in the ftp code both call php_pollfd_for_ms() and immediately abort on any non-zero return instead of retrying on EINTR.
The ext/ftp operations are high-level enough that they should handle EINTR themselves and resume accordingly.

PHP Version

PHP 8.3.13

Operating System

No response

Activity

  1. ndossche commented on Nov 14, 2024

    @ndossche
    Member

    I agree

  2. ndossche commented on Nov 18, 2024

    @ndossche
    Member

    I'm willing to look into this. It's a bit annoying because the polling API does not give us an updated timeout value, so we need to track it ourselves. I thought about using select() instead of poll(), but only on Linux does that actually update the timeout value :(

  3. bukka commented on Nov 24, 2024

    @bukka
    Member

    Was just fixing something similar: #16606

  4. ndossche commented on Nov 24, 2024

    @ndossche
    Member

    Maybe, such a wrapper around the poll functionality should live in a general place

  5. bukka commented on Nov 24, 2024

    @bukka
    Member

    Yeah it could be useful. I see that it's actually timeout reduction does not seems to be always reduced by streams either - EINTR is handled but looks like timeout is not always handled ( e.g.

    do {
    retval = php_pollfd_for(sock->socket, POLLOUT, ptimeout);
    if (retval == 0) {
    sock->timeout_event = 1;
    break;
    }
    if (retval > 0) {
    /* writable now; retry */
    goto retry;
    }
    err = php_socket_errno();
    } while (err == EINTR);
    ).

    We have been discussing new polling API for some time so this is something that should be there for sure. But even having some common helpers in the meantime would be helpful.

  6. added a commit that references this issue on Jan 2, 2025
    a94e5b8
  7. added 2 commits that reference this issue on Jan 3, 2025
    412a6b2
    e90243a
  8. added a commit that references this issue on Jan 3, 2025
    2dfe927
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions