docker / docker/docker-py

Exception not raised for chunked responses from Docker socket

Open
#3,108 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/bug level/apiclient
Dominant language
Python
Stars
7.2k
Forks
1.7k
Avg merge
13d 8h
Merged PRs (30d)
2

Description

This code will only raise an exception (via _result and _raise_for_status) for a non-chunked response:

https://github.com/docker/docker-py/blob/aaf68b7f98df7f886778395112267b9b0f6140bc/docker/api/client.py#L339-L358

This is problematic, because Docker for Mac appears to return errors with a chunked encoding:

POST /v1.35/build?t=repro%3Alatest&q=False&nocache=False&rm=True&forcerm=False&pull=False&dockerfile=Dockerfile&platform=linux%2Famd64 HTTP/1.1
Host: localhost
User-Agent: docker-sdk-python/4.2.2
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Content-Type: application/tar
X-Registry-Config: eyIwN<trimmed>
Content-Length: 10240

<trimmed by me>

HTTP/1.1 500 Internal Server Error
Api-Version: 1.41
Content-Type: application/json
Date: Mon, 17 Apr 2023 04:46:09 GMT
Docker-Experimental: false
Ostype: linux
Server: Docker/20.10.23 (linux)
Transfer-Encoding: chunked


3d
{"message":"Cannot locate specified Dockerfile: Dockerfile"}

0

This means that exceptions are correctly raised on Linux (which doesn't return a chunked response), but not on Mac. Maybe self._raise_for_status(response) can be called unconditionally in _stream_helper, somewhere around line 341?

Docker version info:

Client:
 Cloud integration: v1.0.31
 Version:           20.10.23
 API version:       1.41
 Go version:        go1.18.10
 Git commit:        7155243
 Built:             Thu Jan 19 17:35:19 2023
 OS/Arch:           darwin/arm64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.17.0 (99724)
 Engine:
  Version:          20.10.23
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.10
  Git commit:       6051f14
  Built:            Thu Jan 19 17:31:28 2023
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.6.18
  GitCommit:        2456e983eb9e37e47538f59ea18f2043c9a73640
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read docker/api/client.py around the linked lines, especially _stream_helper, _result, and _raise_for_status, to trace how chunked and non-chunked responses are handled. Confirm the change causes the Dockerfile error in the chunked 500 response to raise an exception while preserving existing behavior for non-chunked responses.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.