Uploaded image for project: 'mod_python'
  1. mod_python
  2. MODPYTHON-180

publisher wrongly generating warning that there is 'nothing to publish'

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.3.x
    • Fix Version/s: 3.3.1
    • Component/s: publisher
    • Labels:
      None

      Description

      Publisher handler contains the code:

      1. we log a message if nothing was published, it helps with debugging
        if (not published) and (req.bytes_sent==0) and (req.next is None):
        log=int(req.get_config().get("PythonDebug", 0))
        if log:
        req.log_error("mod_python.publisher: nothing to publish.")

      The idea is that if the publisher didn't generate any output and simply returned None, that a warning would be generated which might be noticed by a developer and thus be helpful to debugging problems.

      Problem is that "req.bytes_sent" is only actually non zero when data is flushed and actually written back to the client by Apache. It does not take into consideration any buffered data.

      In other words, if "req.write()" is used but second optional argument is always being set to 0 indicating that data should not be flushed, then publisher will wrongly say nothing actually got published.

      Because the PSP classes are no longer flushing data so that output filters like "CONTENT_LENGTH" will work, this will mean you will get this warning all the time when using code like:

      from mod_python import apache, psp

      def index(req):
      page = psp.PSP(req, 'echo.psp')
      page.run()

      Question is, is there a way to determine from Apache that there is buffered data. We don't really want to be adding another special flag in the mod_python request wrapper like req._content_type_set do we???

        Activity

        Hide
        grahamd Graham Dumpleton added a comment -

        Added a new internal (ie., not intended to be used by public), member called _bytes_queued to the request object which tracks number of bytes of data written using req.write() or req.sendfile(). Use this instead of req.bytes_sent, which doesn't take into consideration data still buffered and not processed by any output filters.

        Couldn't see any other way of doing it if we want a warning for case when nothing output by the handler. Note that one could still have cases where the publisher doesn't produce anything, but did set some output header which was then interpreted by an output filter causing the output filter to produce some actual content for the response.

        Being notionally a private member we can always undo this later if we decide to get rid of the warning altogether or we work out a better way of doing it.

        Show
        grahamd Graham Dumpleton added a comment - Added a new internal (ie., not intended to be used by public), member called _bytes_queued to the request object which tracks number of bytes of data written using req.write() or req.sendfile(). Use this instead of req.bytes_sent, which doesn't take into consideration data still buffered and not processed by any output filters. Couldn't see any other way of doing it if we want a warning for case when nothing output by the handler. Note that one could still have cases where the publisher doesn't produce anything, but did set some output header which was then interpreted by an output filter causing the output filter to produce some actual content for the response. Being notionally a private member we can always undo this later if we decide to get rid of the warning altogether or we work out a better way of doing it.

          People

          • Assignee:
            grahamd Graham Dumpleton
            Reporter:
            grahamd Graham Dumpleton
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development