Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-44517

QProcess does not discard buffered data, writes them to new process after start()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.5.0
    • 4.8.6, 5.3.2, 5.4.1
    • Core: I/O
    • None
    • Linux 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt4-3 (2015-02-03) x86_64 GNU/Linux
    • 3f431e279aab16465496cc0de03a1af874c1ce65

    Description

      If QProcess' write buffer has some data before start(), it will be
      send to the new process.

      I'm not sure if it is by design or not, but there seems no way to discard
      them so that the new process can start fresh after error exit of the
      last process.

          // think that this is server process and it dies while communicating
          qDebug() << "-- server #0 starting --";
          proc.start("sleep 0.1");
          proc.waitForStarted();
          for (int i = 0; i < 10000; i++)  // large enough to make them buffered
              proc.write("hello world\n");
          proc.waitForFinished();
      
          // remainder of IPC message is still kept in write buffer of QProcess.
          // main process want to discard it, but it seems not possible.
          qDebug() << "-- server #0 died --";
          qDebug() << "error:" << proc.error() << "(4: WriteError)";
          qDebug() << "bytesToWrite:" << proc.bytesToWrite();
          proc.close();
          qDebug() << "bytesToWrite (after close):" << proc.bytesToWrite();
      
          // main process notices the server died, so restarts it. the new server
          // process receives the remainder of the last message, which would cause
          // sort of communication protocol error.
          qDebug() << "-- server #1 starting --";
          proc.start("wc -c");
          proc.waitForStarted();
          proc.closeWriteChannel();
          proc.waitForFinished();
          qDebug() << "received:" << proc.readLine() << "[bytes]";
      

      Attached the code to reproduce this problem.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            yuja Yuya Nishihara
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes