build_job() is failing with "... empty response" exception when Jenkins is behind haproxy where disabled keep_alive

Bug #1775047 reported by Dennis Dmitriev
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Python Jenkins
Fix Released
Undecided
Dennis Dmitriev

Bug Description

Jenkins supports keep_alive http option, and when JenkinsClient:build_job() is called, normally the response contains the 'content-length' header, for example:

  ipdb> response.status_code
  201
  ipdb> response.headers
  {'Date': 'Mon, 04 Jun 2018 11:52:00 GMT', 'Content-Length': '0', 'Location': 'http://10.70.0.15:8081/queue/item/11/', 'X-Content-Type-Options': 'nosniff', 'Server': 'Jetty(9.4.z-SNAPSHOT)'}

But if Jenkins master is behind HAProxy with enabled 'option httpclose', which disables keep_alive, the response doesn't contain 'content-length' header:

  ipdb> response.status_code
  201
  ipdb> response.headers
  {'Date': 'Mon, 04 Jun 2018 11:55:36 GMT', 'Connection': 'close', 'Location': 'http://10.60.0.90:8081/queue/item/16/', 'X-Content-Type-Options': 'nosniff', 'Server': 'Jetty(9.4.z-SNAPSHOT)'}

Other fields that are checked in JenkisClient:_response_handler() are empty in both cases:
  ipdb> response.content
  ''
  ipdb> response.text
  u''

As the result: JenkinsClient raises an exception like:

  File ".../local/lib/python2.7/site-packages/jenkins/__init__.py", line 1280, in build_job
    'POST', self.build_job_url(name, parameters, token)))
  File ".../lib/python2.7/site-packages/jenkins/__init__.py", line 565, in jenkins_request
    self._request(req))
  File ".../lib/python2.7/site-packages/jenkins/__init__.py", line 523, in _response_handler
    "empty response" % self.server)
jenkins.EmptyResponseException: Error communicating with server[http://10.60.0.90:8081/]: empty response

However, the response is valid because the meaningful part of the response is the header 'Location'.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-jenkins (master)

Fix proposed to branch: master
Review: https://review.openstack.org/572179

Changed in python-jenkins:
assignee: nobody → Dennis Dmitriev (ddmitriev)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-jenkins (master)

Reviewed: https://review.openstack.org/572179
Committed: https://git.openstack.org/cgit/openstack/python-jenkins/commit/?id=f420d6de01de4558a8f285deaedae58cbc4cb743
Submitter: Zuul
Branch: master

commit f420d6de01de4558a8f285deaedae58cbc4cb743
Author: Dennis Dmitriev <email address hidden>
Date: Mon Jun 4 21:02:20 2018 +0300

    Check for 'Location' header in the response

    If the keep_alive is not available because of using reverse
    proxy, the header 'Content-Lenght' may not be available,
    causing the exception:

     Error communicating with server[...]: empty response

    However, if 'Location' header is present, the response is valid.

    Add unit tests:
    - build_job must pass even if no 'content-lenght'
      in response header
    - build_job must fail if no 'location' in response header

    Change-Id: I4da6dd19f9d8302a76652a3686a9377f9a2503a6
    Closes-Bug:#1775047

Changed in python-jenkins:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.