Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

IPP 1-second timeout causing connection errors on congested network #1719

Closed

Description

@michaelrsweet

Version: 1.1.23
CUPS.org User: carey

This bug is similar to STR #377, but related to the IPP server, not the client.

We're running some PCs with Debian GNU/Linux 3.1 and CUPS 1.1.23 in remote locations over rather slow and busy WAN connections. The client is running OS/400 V5R2 with the latest fixes applied, which uses chunked encoding on IPP connections.

On these links, with frequent print jobs being sent, it's not unusual for the TCP packet containing the chunk length of the IPP attributes or a block of print data to be dropped, and eventually resent, but after more than a second. In this case, the call to httpWait(1000) in ipp_read_http will have returned with no data received.

Depending on when this occurs, CUPS will either send an immediate 400 Bad Request response, or it will queue all the data received so far to the printer and send a 200 OK, then a 400 Bad Request when the subsequent print data isn't an HTTP request.

It would help if CUPS noticed that it hadn't received the final chunk and logged a message to that effect before closing the connection, instead of successfully queueing the partial printout.

I've compiled a version of CUPS with a much longer timeout, which shouldn't cause any problems since the OS/400 machine is the only client, and I'll update this bug when I've had a chance to try it out.

I've attached an extract from the log file with identifying features filed off.

Activity

  1. michaelrsweet commented on May 23, 2006

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: carey

    I guess this is the second problem mentioned in STR #1020. In our case it's not hypothetical, but a serious problem affecting multiple printers.

    Compared to the denial of service that can be caused by someone authorised to the printer when the delay is too long, CUPS is vulnerable to any DOS that makes the server or an intermediate router drop incoming packets.

  2. michaelrsweet commented on May 23, 2006

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: mike

    Regarding the timeout, I am hesitant to increase the timeout because it has a much greater potential for denial-of-service. Also, if your network is that congested, you already have bigger problems...

    Regarding the potential for denial-of-service, that is an issue for any service and there is no way to avoid it.

    Anyways, I don't think this will be "fixed" any time soon...

  3. michaelrsweet commented on May 30, 2006

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: mike

    How has the longer timeout worked for you?

  4. michaelrsweet commented on May 31, 2006

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: carey

    The longer timeout in ipp_read_http seems to have made things better. However, I'm now seeing problems with the HTTP chunked encoding which may be similar. I plan to look into this more closely sometime tomorrow.

  5. michaelrsweet commented on Jun 1, 2006

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: mike

    Please let me know how things turn out with this...

    Also, what timeout value have you used?

  6. michaelrsweet commented on Jun 2, 2006

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: carey

    I'd changed the timeout to 30 seconds, more to see what would happen than by any calculation.

    The second timeout I'm seeing is between the chunk-data and CRLF. If it takes more than a second for CUPS to receive the CRLF after the last byte of a chunk, it sees the successful end of the transfer, spools the data, and sends a 200 OK response. It then skips that CRLF, the chunk-size and the next CRLF, and parses the first line of the next chunk as a new HTTP request.

    I haven't investigated the code yet to see where this happens, or whether CUPS 1.2 does the same.

    If it's infeasible to stop CUPS timing out so quickly, it would be nice if the HTTP response was 408 Request Timeout instead of just 400 Bad Request, which would save a lot of time investigating these timeouts when they do happen.

    In no case should CUPS be continuing blithely on when it has timed out in the middle of reading chunked data. It would make sense to discard the print job so far and send back a 400 or 408 response code, then close the connection once the client has received the error.

  7. michaelrsweet commented on Jun 2, 2006

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: mike

    In 1.2, httpGets() correctly returns an error with ETIMEDOUT set, so that particular error should not be a problem.

    I've attached a patch to 1.2.1 which increases the timeout to 10 seconds for both IPP and HTTP chunks; please let me know if that is sufficient in your configuration.

  8. michaelrsweet commented on Jun 26, 2006

    @michaelrsweet
    ContributorAuthor

    "str1719.patch":

    Index: http.c

    --- http.c (revision 5622)
    +++ http.c (working copy)
    @@ -866,7 +866,7 @@
    * No newline; see if there is more data to be read...
    */

    •  if (!http->blocking && !http_wait(http, 1000))
      
    •  if (!http->blocking && !http_wait(http, 10000))
      

      {
      DEBUG_puts("httpGets: Timed out!");
      http->error = ETIMEDOUT;
      @@ -1222,7 +1222,7 @@

      • Buffer small reads for better performance...
        */
    • if (!http->blocking && !httpWait(http, 1000))

    • if (!http->blocking && !httpWait(http, 10000))
      return (0);

    if (http->data_remaining > sizeof(http->buffer))
    @@ -1285,7 +1285,7 @@
    #ifdef HAVE_SSL
    else if (http->tls)
    {

    • if (!http->blocking && !httpWait(http, 1000))
    • if (!http->blocking && !httpWait(http, 10000))
      return (0);

    bytes = http_read_ssl(http, buffer, length);
    @@ -1293,7 +1293,7 @@
    #endif /* HAVE_SSL */
    else
    {

    • if (!http->blocking && !httpWait(http, 1000))
    • if (!http->blocking && !httpWait(http, 10000))
      return (0);

    DEBUG_printf(("httpRead2: reading %d bytes from socket...\n", length));

    Index: ipp.c

    --- ipp.c (revision 5622)
    +++ ipp.c (working copy)
    @@ -2742,10 +2742,10 @@
    if (!http->blocking)
    {
    /*

    •    \* Wait up to 1 second for more data on non-blocking sockets...
      
    •    * Wait up to 10 seconds for more data on non-blocking sockets...
      

      */

    • if (!httpWait(http, 1000))

    • if (!httpWait(http, 10000))
      {
      /*
      * Signal no data...

  9. added this to the Stable milestone on Mar 17, 2016
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions