swagger-api / swagger-api/swagger-codegen
[python] generated client crashes with `error(32, 'Broken pipe')` while uploading file
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I am trying to upload a file from python client to go server. I am using following swagger conf to generate python client
/upload:
post:
tags:
description: upload file
operationId: UploadFile
consumes:
- multipart/form-data
parameters:
- in: formData
name: file.tar
type: file
format: binary
responses:
'200':
description: Success
schema:
$ref: '#/definitions/Success'
'401':
description: Unauthorized
schema:
$ref: '#/definitions/UnauthorizedError'
This works perfectly if the server reads the complete body and then sends a response to the client. But if the server returns some response without reading/parsing request body, the python client crashes with urllib3.exceptions.ProtocolError: ('Connection aborted.', error(32, 'Broken pipe'))
File "/usr/lib/python2.7/httplib.py", line 1042, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python2.7/httplib.py", line 1082, in _send_request
self.endheaders(body)
File "/usr/lib/python2.7/httplib.py", line 1038, in endheaders
self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 882, in _send_output
self.send(msg)
File "/usr/lib/python2.7/httplib.py", line 858, in send
self.sock.sendall(data)
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
urllib3.exceptions.ProtocolError: ('Connection aborted.', error(32, 'Broken pipe'))
My observation is, the python client tries to upload the file or write data even after server closes the connection from its end. I can catch the signal SIGPIPE in python client when this occurs
Swagger-codegen version
swagger-codegen-cli 2.2.3
Swagger declaration file content or url
docker run --rm -t -v pwd:/data jimschubert/swagger-codegen-cli:2.2.3 generate --git-user-id userid --git-repo-id api_python -c /data/swagger-codegen-config.json -i /data/swagger .yaml -l python -o /data/python-client
Steps to reproduce
- Generate a python client with above swagger configuration
- Upload file to the server using generated API
- Return response from the server without parsing/reading request body/file.
Suggest a fix/enhancement
Python client seems to be sending data even after the connection is closed from server end hance gets SIGPIPE signal. Need to handle this the way curl does
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Use the supplied Swagger definition and generation command to produce the Python client, then reproduce the upload against a server that responds without reading the request body. Inspect the generated client’s multipart upload path and compare its behavior with the requested curl-like handling. Done means an early server close no longer produces an uncaught broken-pipe failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100