Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload fails with "Broken Pipe" #335

Open
TyrfingMjolnir opened this issue Jan 28, 2019 · 12 comments
Open

Upload fails with "Broken Pipe" #335

TyrfingMjolnir opened this issue Jan 28, 2019 · 12 comments

Comments

@TyrfingMjolnir
Copy link

$ asciinema upload /var/folders/v2/g27ngtds20zg60cy_f2jb_l80000gn/T/tmpub1dsng9-ascii.cast
asciinema: upload failed: <urlopen error [Errno 32] Broken pipe>
asciinema: retry later by running: asciinema upload /var/folders/v2/g27ngtds20zg60cy_f2jb_l80000gn/T/tmpub1dsng9-ascii.cast

Here is the app in tmp-folder

$ exa -l  /var/folders/v2/g27ngtds20zg60cy_f2jb_l80000gn/T/tmpub1dsng9-ascii.cast
.rw------- 5.8M user 28 Jan 16:33 /var/folders/v2/g27ngtds20zg60cy_f2jb_l80000gn/T/tmpub1dsng9-ascii.cast
@crazymerlyn
Copy link
Contributor

Not sure why you aren't getting a proper error message but there is 5M limit on upload files. See #91

@ku1ik
Copy link
Contributor

ku1ik commented Mar 2, 2019

Yes, that's size limit issue.

asciinema does have error handler for status 413 (which is returned by web server in this case) but it seems it's never properly handled due to how Python's urllib operates. You can read more about the problem here: psf/requests#2422 (comment)

@ku1ik ku1ik changed the title How to fix this issue? Upload fails with "Broken Pipe" Mar 17, 2019
@emaste
Copy link

emaste commented Oct 29, 2019

Ran into the same problem today. What do you think about a stopgap measure of emitting a warning client side if the file to be uploaded is over 5M?

@dankamongmen
Copy link

I'm regularly running into it well below the 5M limit.

[schwarzgerat](2) $ ls -l /tmp/user/1000/tmpaxpadd2n-ascii.cast 
-rw------- 1 dank dank 592498 2020-01-05 08:57 /tmp/user/1000/tmpaxpadd2n-ascii.cast
[schwarzgerat](0) $ asciinema upload /tmp/user/1000/tmpaxpadd2n-ascii.cast 
asciinema: upload failed: <urlopen error [Errno 32] Broken pipe>
asciinema: retry later by running: asciinema upload /tmp/user/1000/tmpaxpadd2n-ascii.cast
[schwarzgerat](1) $ 

That one's only 600K. Plays perfectly locally.

@nbraud
Copy link

nbraud commented Jan 17, 2020

Can reproduce here:

$ asciinema upload display_sweep.cast
asciinema: upload failed: <urlopen error [Errno 32] Broken pipe>
asciinema: retry later by running: asciinema upload display_sweep.cast

$ ll -h display_sweep.cast
-rw-r--r-- 1 nicoo nicoo 2.3M Jan 14 21:29 display_sweep.cast

Same thing happens on smaller files too. I tried to reproduce with curl but this worked fine:

$ curl --http1.1 -v -u $USER:$(cat ~/.config/asciinema/install-id) https://asciinema.org/api/asciicasts -F asciicast=@display_sweep.cast
*   Trying 109.107.38.78:443...
* TCP_NODELAY set
* Connected to asciinema.org (109.107.38.78) port 443 (#0)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: CN=asciinema.org
*  start date: Jan 16 08:09:20 2020 GMT
*  expire date: Apr 15 08:09:20 2020 GMT
*  subjectAltName: host "asciinema.org" matched cert's "asciinema.org"
*  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
*  SSL certificate verify ok.
* Server auth using Basic with user 'nicoo'
> POST /api/asciicasts HTTP/1.1
> Host: asciinema.org
> Authorization: Basic XXXXSECRETVALUEHERE
> User-Agent: curl/7.67.0
> Accept: */*
> Content-Length: 2332762
> Content-Type: multipart/form-data; boundary=------------------------8506bb168e19a8c6
> Expect: 100-continue
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
* Mark bundle as not supporting multiuse
< HTTP/1.1 201 Created
< Cache-Control: max-age=0, private, must-revalidate
< Content-Length: 78
< Content-Type: text/plain; charset=utf-8
< Date: Fri, 17 Jan 2020 16:47:43 GMT
< Location: https://asciinema.org/a/ucRJ70xKSlhN1QlmMW0BdSUBf
< Server: Caddy
< Server: nginx
< Strict-Transport-Security: max-age=15768000
< X-Request-Id: 2nlbkv35ad6doecmo07jcdm2
< 
View the recording at:

    https://asciinema.org/a/ucRJ70xKSlhN1QlmMW0BdSUBf
* Connection #0 to host asciinema.org left intact

This seems to be an issue specific to asciinema's HTTP API client; I encountered it even when installing asciinema form pip in a fresh venv; the local python version is 3.7.5 (as packaged in Debian 11/testing)

@ulidtko
Copy link

ulidtko commented Jun 11, 2020

Not sure why you aren't getting a proper error message but there is 5M limit on upload files. See #91

This should be an FAQ item.

As soon as I saw that "broken pipe" repeated twice, I suspected my 6.3M cast exceeded the upload limit.

But actually finding this thread took... uhhh... 24 minutes. Around 15 of which I was messing with discobot certification, hoping that'd allow me to post the question in the FAQ discourse section (it didn't).

@sontek
Copy link

sontek commented Nov 30, 2020

I'm getting this error with a small one:

asciinema: recording finished
asciinema: press <enter> to upload to asciinema.org, <ctrl-c> to save locally
asciinema: upload failed: <urlopen error [Errno 32] Broken pipe>
asciinema: retry later by running: asciinema upload /tmp/tmpe_sntawl-ascii.cast
sontek@hulk:/mnt/c/Users/sontek/code/snowmachine$ du -sh /tmp/tmpe_sntawl-ascii.cast
184K    /tmp/tmpe_sntawl-ascii.cast
sontek@hulk:/mnt/c/Users/sontek/code/snowmachine$

Tried uploading it later too:

sontek@hulk:/mnt/c/Users/sontek/code/snowmachine$ asciinema upload /tmp/tmpe_sntawl-ascii.cast
asciinema: upload failed: <urlopen error [Errno 32] Broken pipe>
asciinema: retry later by running: asciinema upload /tmp/tmpe_sntawl-ascii.cast

@josevnz
Copy link

josevnz commented Apr 22, 2022

Maybe the client could stop the upload altogether before it happens. I checked the code and the sizes of the chunks are known in advance before they are uploaded to the server (urllib_http_adapter.py):

class MultipartFormdataEncoder:
    def __init__(self):
        self.boundary = uuid.uuid4().hex
        self.content_type = 'multipart/form-data; boundary={}'.format(self.boundary)

    @classmethod
    def u(cls, s): 
        if sys.hexversion >= 0x03000000 and isinstance(s, bytes):
            s = s.decode('utf-8')
        return s

    def iter(self, fields, files):
        """
        fields is a dict of {name: value} for regular form fields.
        files is a dict of {name: (filename, file-type)} for data to be uploaded as files
        Yield body's chunk as bytes
        """
        encoder = codecs.getencoder('utf-8')
        for (key, value) in fields.items():
            key = self.u(key)
            yield encoder('--{}\r\n'.format(self.boundary))
            yield encoder(self.u('Content-Disposition: form-data; name="{}"\r\n').format(key))
            yield encoder('\r\n')
            if isinstance(value, int) or isinstance(value, float):
                value = str(value)
            yield encoder(self.u(value))
            yield encoder('\r\n')
        for (key, filename_and_f) in files.items():
            filename, f = filename_and_f
            key = self.u(key)
            filename = self.u(filename)
            yield encoder('--{}\r\n'.format(self.boundary))
            yield encoder(self.u('Content-Disposition: form-data; name="{}"; filename="{}"\r\n').format(key, filename))
            yield encoder('Content-Type: application/octet-stream\r\n')
            yield encoder('\r\n')
            data = f.read()
            yield (data, len(data))
            yield encoder('\r\n')
        yield encoder('--{}--\r\n'.format(self.boundary))

By the time we know 'yield (data, len(data))' we could thrown an exception and stop the upload because we know it will fail.

As a side note, I captured the traffic between my machine and the asciinema website with tcpdump (analized with wireshark), here is the whole conversation until we get dumped because the file is too big:

POST /api/asciicasts HTTP/1.1
Accept-Encoding: identity
Content-Length: 12444474
Host: asciinema.org
User-Agent: asciinema/2.0.2 CPython/3.9.9 Linux/5.14.18-100.fc33.x86_64-x86_64-with-glibc2.32
Accept: application/json
Content-Type: multipart/form-data; boundary=d5c6b2543ee94511943126c6a3c5d33a
Authorization: Basic XXXXX=
Connection: close

--d5c6b2543ee94511943126c6a3c5d33a
Content-Disposition: form-data; name="asciicast"; filename="ascii.cast"
Content-Type: application/octet-stream

{"version": 2, "width": 203, "height": 32, "timestamp": 1650568938, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}}
[0.191182, "o", "\u001b]777;notify;Command completed;eve_log.py --format table --timestamp '2022-02-23T18:22:24.405139+0000' test/eve.json\u001b\\\u001b]777;precmd\u001b\\\u001b]0;josevnz@dmaf5:~/SuricataLog-Logging-features-branch\u001b\\"]
[0.19215, "o", "\u001b]7;file://dmaf5/home/josevnz/SuricataLog-Logging-features-branch\u001b\\"]
[0.192399, "o", "[josevnz@dmaf5 SuricataLog-Logging-features-branch]$ "]
[1.000538, "o", "Let me show you how you can filter your Suricata alerts, displaying the results in different formats"]
[4.506902, "o", "\r\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C"]
[4.921813, "o", "\u001b[1@#"]
[5.170393, "o", "\u001b[1@ "]
[5.538486, "o", "\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C"]
[6.914337, "o", "\r\n"]
[6.918708, "o", "\u001b]777;notify;Command completed;# Let me show you how you can filter your Suricata alerts, displaying the results in different formats\u001b\\\u001b]777;precmd\u001b\\\u001b]0;josevnz@dmaf5:~/SuricataLog-Logging-features-branch\u001b\\"]
[6.920219, "o", "\u001b]7;file://dmaf5/home/josevnz/SuricataLog-Logging-features-branch\u001b\\"]
[6.920352, "o", "[josevnz@dmaf5 SuricataLog-Logging-features-branch]$ "]
[8.202111, "o", "1"]
[8.658197, "o", ")"]
[8.962176, "o", " "]
[10.153862, "o", "A"]
[10.409632, "o", " "]
[10.61679, "o", "n"]
[10.777002, "o", "i"]
[10.881112, "o", "c"]
[10.952884, "o", "e"]
[11.088641, "o", " "]
[11.201045, "o", "t"]
[11.466022, "o", "a"]
[11.553785, "o", "b"]
[11.818412, "o", "l"]
[11.961808, "o", "e"]
[13.51443, "o", "\r\n"]
[13.514675, "o", "bash: syntax error near unexpected token `)'\r\n"]
[13.518913, "o", "\u001b]777;notify;Command completed;1) A nice table\u001b\\\u001b]777;precmd\u001b\\\u001b]0;josevnz@dmaf5:~/SuricataLog-Logging-features-branch\u001b\\"]
[13.520551, "o", "\u001b]7;file://dmaf5/home/josevnz/SuricataLog-Logging-features-branch\u001b\\"]
[13.52072, "o", "[josevnz@dmaf5 SuricataLog-Logging-features-branch]$ "]
[22.176716, "o", "eve_log.py --format table --timestamp '2022-02-23T18:22:24.405139+0000' test/eve.jso"]
[24.202009, "o", "n"]
[26.097822, "o", "\r\n"]
[26.098024, "o", "\u001b]777;preexec\u001b\\"]
[26.312676, "o", "\u001b[?1049h\u001b[H\u001b[?1000h\u001b[?1003h\u001b[?1015h\u001b[?1006h\u001b[?25l\u001b[?1003h\r\n"]
[26.314059, "o", "\u001bP=1s\u001b\\\u001b[H\u001b[H                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                               "]
[26.314299, "o", "            \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                              "]
[26.314387, "o", "             \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                             "]
[26.314455, "o", "              \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                            "]
[26.314502, "o", "               \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                           "]
[26.31456, "o", "                \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                          "]
[26.314616, "o", "                 \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \u001bP=2s\u001b\\"]
[26.31467, "o", "\u001bP=1s\u001b\\\u001b[H\u001b[H                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                               "]
[26.314714, "o", "            \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                              "]
[26.314781, "o", "             \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                             "]
[26.314843, "o", "              \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                            "]
[26.314902, "o", "               \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                           "]
[26.314957, "o", "                \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                          "]
[26.315012, "o", "                 \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \u001bP=2s\u001b\\"]
[26.316033, "o", "\u001b[?25l"]
[26.318086, "o", "\r\u001b[2KParsing test/eve.json \u001b[38;5;237m........................................................................................................................\u001b[0m \u001b[35m  0%\u001b[0m \u001b[36m-:--:--\u001b[0m"]
[26.378123, "o", "\r\u001b[2KParsing test/eve.json \u001b[38;2;114;156;31m........................................................................................................................\u001b[0m \u001b[35m100%\u001b[0m \u001b[36m0:00:00\u001b[0m\r\n\u001b[?25h"]
[26.390312, "o", "\u001bP=1s\u001b\\\u001b[H\u001b[H                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                               "]
[26.39044, "o", "            \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                              "]
[26.390499, "o", "             \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                             "]
[26.390559, "o", "              \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                            "]
[26.390615, "o", "               \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                           "]
[26.39064, "o", "                \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                          "]
[26.390719, "o", "                 \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \u001bP=2s\u001b\\"]
[26.390868, "o", "\u001bP=1s\u001b\\\u001b[H\u001b[H                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                               "]
[26.390893, "o", "            \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                              "]
[26.390944, "o", "             \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                             "]
[26.391027, "o", "              \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                            "]
[26.391091, "o", "               \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                           "]
[26.391116, "o", "                \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                          "]
[26.391172, "o", "                 \r\n                                                                                                                                                                                                           \r\n                                                                                                                                                                                                           \u001bP=2s\u001b\\"]
[26.431391, "o", "\u001bP=1s\u001b\\\u001b[H\u001b[3m                                                                                      Suricata alerts for 2022-02-23 18:22:24.405139, logs=test/eve.json                                                   \u001b[0m\r\n.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................\r\n...\u001b[1;35m \u001b[0m\u001b[1;35mTimestamp                      \u001b[0m\u001b[1;35m \u001b[0m...\u001b[1;35m \u001b[0m\u001b[1;35mSeverity\u001b[0m\u001b[1;35m \u001b[0m...\u001b[1;35m \u001b[0m\u001b[1;35mSignature                                           \u001b"]
[26.431543, "o", "[0m\u001b[1;35m \u001b[0m...\u001b[1;35m \u001b[0m\u001b[1;35mProtocol\u001b[0m\u001b[1;35m \u00HTTP/1.1 413 Request Entity Too Large
Content-Length: 176
Content-Type: text/html
Date: Fri, 22 Apr 2022 11:17:19 GMT
Server: nginx
Connection: close

<html>
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>nginx</center>
</body>
</html>

@ulidtko
Copy link

ulidtko commented Apr 23, 2022

@josevnz your're right, but it wouldn't be wise to hardcode a serverside config value (the 5M) in the client...

IMO what should happen instead, is adequate error reporting. Instead of this:

asciinema: upload failed: <urlopen error [Errno 32] Broken pipe>

it should show this:

asciinema: upload failed: server replied 413 Request Entity Too Large

@josevnz
Copy link

josevnz commented Apr 25, 2022 via email

@ku1ik
Copy link
Contributor

ku1ik commented Jul 2, 2023

What do you think about a stopgap measure of emitting a warning client side if the file to be uploaded is over 5M?

Maybe the client could stop the upload altogether before it happens. I checked the code and the sizes of the chunks are known in advance before they are uploaded to the server (urllib_http_adapter.py):

I agree with @ulidtko that hardcoding the limit on the client side is a brittle way of solving this. The limit has been changing on the server side over time (2 MB -> 5 MB -> 8 MB), and asciinema recorder distributed in various package repositories isn't always the freshest one (we still have even 8 year old versions uploading recordings, which I'm happy about).

IMO what should happen instead, is adequate error reporting. Instead of this:

it should show this:

asciinema: upload failed: server replied 413 Request Entity Too Large

That was desired behavior for a long time, we had this forever:

413: "Sorry, the size of your recording exceeds the server-configured limit.",

The problem is psf/requests#2422 (comment) , which breaks this code's expectation. This is deep in Python's stdlib and unlikely to be fixed anytime soon (feel free to read the thread).

Anyway, today I've removed the limit configuration for asciinema.org on nginx level but kept default limit of 8 MB in application server's config (Phoenix/Plug/Cowboy). It seems it has fixed the problem of bad client error message 🎉 😅 (while still returning 413, just not from nginx). The limit of 8 MB is still enforced though.

Future improvement could be to display current limit in the error message. If we continue relying on 413 then web server (or loadbalancer) could be configured to add extra response header with limit value to the response for all 413 responses, then the client could look for the header and embed it in the error message if present.

Or as you say we handle the 413 error code differently instead of sending it back with the Nginx error message back to the client.

That 413 thing has been causing a lot of trouble due to how inadequate Python urllib is with regards to handling premature connection close on 4xx errors (I tried with Python's requests library but it's the same, as it relies on urllib internally). Application-level check/response would potentially workaround this urllib problem. On the other hand HTTP status 413 seems to be the most standard, correct and easy (at least in theory) way of handling upload size limit. I guess we could even combine both - still use 413 but return it from web app's controller instead of from web framework's (or load balancer's) request parser.

@ku1ik
Copy link
Contributor

ku1ik commented Feb 9, 2024

The new version of the CLI (the Rust rewrite) handles 413 much better. I tested it with several scenarios and in all cases it properly displays user friendly message. It's not released yet, but it's pretty stable and can be used already (see https://discourse.asciinema.org/t/testing-the-new-rust-version-of-the-asciinema-cli/778/10).

I'll see if I can add an additional response header with a value of the current server configured limit. The web server (Phoenix/Cowboy) doesn't let me do it easily so I'll most likely need to do it at the load balancer level (currently using Caddy). If this works out then the CLI could read this header when getting 413 and add the limit value to the error message that is displayed.

Speaking of server limit, if you self-host the asciinema server you can now easily change the upload limit: https://docs.asciinema.org/manual/server/self-hosting/configuration/#upload-size-limit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants