ConnectionResetError raised in case a build_arg has incorrect type and a build context folder contains large file
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.7k
- Avg merge
- 13d 8h
- Merged PRs (30d)
- 2
Description
Hello.
I passed a boolean value as a build argument by mistake and found that it hangs on Windows and raises Connection reset by peer exception on Linux:
Traceback
Traceback (most recent call last):
File "/home/user/.local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen
chunked=chunked,
File "/home/user/.local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 387, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.7/http/client.py", line 1252, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1298, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1247, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1065, in _send_output
self.send(chunk)
File "/usr/lib/python3.7/http/client.py", line 987, in send
self.sock.sendall(data)
ConnectionResetError: [Errno 104] Connection reset by peer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/user/.local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/home/user/.local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 720, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/home/user/.local/lib/python3.7/site-packages/urllib3/util/retry.py", line 400, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/home/user/.local/lib/python3.7/site-packages/urllib3/packages/six.py", line 734, in reraise
raise value.with_traceback(tb)
File "/home/user/.local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen
chunked=chunked,
File "/home/user/.local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 387, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.7/http/client.py", line 1252, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1298, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1247, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1065, in _send_output
self.send(chunk)
File "/usr/lib/python3.7/http/client.py", line 987, in send
self.sock.sendall(data)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "docker_false_arg.py", line 14, in <module>
decode=True)
File "/home/user/.local/lib/python3.7/site-packages/docker/api/build.py", line 269, in build
timeout=timeout,
File "/home/user/.local/lib/python3.7/site-packages/docker/utils/decorators.py", line 46, in inner
return f(self, *args, **kwargs)
File "/home/user/.local/lib/python3.7/site-packages/docker/api/client.py", line 233, in _post
return self.post(url, **self._set_request_timeout(kwargs))
File "/home/user/.local/lib/python3.7/site-packages/requests/sessions.py", line 590, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/home/user/.local/lib/python3.7/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/home/user/.local/lib/python3.7/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/home/user/.local/lib/python3.7/site-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
This behavior occurs only if a build context folder contains a large file or files (>1 MB). Otherwise, the error message about incorrect type is displayed.
Environment:
- docker-py 5.0.0
- Docker Engine 20.10.3
How to reproduce:
- Create an empty folder and cd to it
- Place this example script and Dockerfile in the folder:
FROM alpine
ARG bool_arg
RUN echo $bool_arg
import docker
import os
build_args = {'bool_arg': True}
location = os.getcwd()
client = docker.from_env()
log = client.api.build(path=location,
tag='test_bool_arg:latest',
dockerfile='test.dockerfile',
rm=True,
nocache=True,
pull=True,
buildargs=build_args,
decode=True)
for line in log:
for _, value in line.items():
print(f'{value}')
- Launch script and get message
error reading build args: json: cannot unmarshal bool into Go value of type string - Create a large file in the folder (
truncate -s 1M dummy_file) - Launch script again and get ConnectionResetError
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
Reproduce the failure with docker_false_arg.py, the Dockerfile, and a build context containing a 1 MB file. Start at the docker.api.build call shown in the traceback and trace how build arguments and the context are sent. Done means an invalid boolean build argument produces a consistent, readable error instead of hanging or raising ConnectionResetError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100