channels icon indicating copy to clipboard operation
channels copied to clipboard

File upload never ends?

Open ckcollab opened this issue 6 years ago • 13 comments

On MacOSX with Docker and the following versions of relevant libraries:

channels==2.0.2
Django==2.0.2
djangorestframework==3.7.7
daphne==2.0.3
asgiref==2.1.6

(I also tried a pip install -U -r requirements.txt to try and catch any new versions, believe I did that properly and didn't see any available upgrades)

I found this thread with a similar problem #753 and the problem seems to have been solved, but I experience a successful POST + upload with no response from the server (it just perpetually hangs).

django_1          | [2018/02/22 04:54:16] HTTP GET /api/submissions/ 200 [0.11, 172.19.0.1:57416]
django_1          | 2018-02-22 04:54:26,527 - WARNING - server - Application instance 
<Task pending coro=<AsgiHandler.__call__() running at /usr/local/lib/python3.6/site-packages/channels/http.py:191> 
wait_for=<Future pending cb=[_chain_future.<locals>._call_check_cancel() at /usr/local/lib/python3.6/asyncio/futures.py:403, <TaskWakeupMethWrapper object at 0x7fe1ac309b58>()]>> 
for connection <WebRequest at 0x7fe1ac305588 method=POST uri=/api/submissions/ clientproto=HTTP/1.1> took too long to shut down and was killed.

What is so confusing is that everything seems to work fine, but I just don't get a response. The object is created, the file is successfully uploaded..

A little unsure how best to debug this, not very familiar with ASGI/async/channels. Would appreciate a push in the right direction and I apologize if this issue is too vague

Everything else about channels seems to be working swell, don't mean to sound ungrateful! Thanks so much for releasing this and all the hard work :)

ckcollab avatar Feb 22 '18 05:02 ckcollab

Can I get a bit more clarification if you can?

  • Is this posting to a Django view or a custom consumer?
  • Does it happen with all file sizes?
  • I presume you're using <input type="file" ... >?

andrewgodwin avatar Feb 22 '18 05:02 andrewgodwin

Is this posting to a Django view or a custom consumer?

DRF view via the DRF api browser form

Does it happen with all file sizes?

I had previously only used a 1KB file. Just to test things out I used a 400mb file and ended up with the same result. Upload worked, I can download the 400mb file from the object, but server is hanging there.

I presume you're using <input type="file" ... >?

Yessir.

Thank you for the help!

ckcollab avatar Feb 22 '18 05:02 ckcollab

Oh, it's specifically DRF? Hm. Does it work if you do it via a normal Django view?

andrewgodwin avatar Feb 22 '18 05:02 andrewgodwin

Oh, it's specifically DRF?

Well, that was my assumption based on the issue I saw, but now I am seeing that it is more. I made a test view... fails the same way!

Here's my code:

# Form and model
class SubmissionForm(forms.ModelForm):
    class Meta:
        model = Submission
        fields = ('name', 'zip_file', 'phase')


class SubmissionUpload(CreateView):
    template_name = 'competitions/test_submission_form.html'
    model = Submission
    form_class = SubmissionForm

# and maybe relevant, here are the contents of my "routing.py"
from channels.routing import ProtocolTypeRouter

application = ProtocolTypeRouter({
    # Empty for now (http->django views is added by default)
})
{% block content %}
    <form method="POST" enctype="multipart/form-data">
        {{ form.as_p }}
        {% csrf_token %}
        <input type="submit" value="submit">
    </form>
{% endblock %}

So strange. Again, I can see the file/Submission just fine. No response though and this message:

django_1          | 2018-02-22 05:31:16,069 - WARNING - server - Application instance <Task pending coro=<AsgiHandler.__call__() running at /usr/local/lib/python3.6/site-packages/channels/http.py:191> wait_for=<Future pending cb=[_chain_future.<locals>._call_check_cancel() at /usr/local/lib/python3.6/asyncio/futures.py:403, <TaskWakeupMethWrapper object at 0x7ffb6048ed98>()]>> for connection <WebRequest at 0x7ffb60489f28 method=POST uri=/competitions/test_submission/?name=asdf&zip_file=eStmt_2018-01-31.pdf&phase=2&csrfmiddlewaretoken=7duNcRvL3E3dJZSdPTB3UZKTsofHE7FuJjksvNXrQeRbh5b8aqqZXVKZ4bPH0xg8 clientproto=HTTP/1.1> took too long to shut down and was killed.

I'm probably doing something very stupid so I apologize. Hopefully at least this helps someone in the future!

ckcollab avatar Feb 22 '18 05:02 ckcollab

This is likely a bug in Channels, actually - there's not any POST body tests right now and I don't manually check it very often. I'll take a look at it soon.

andrewgodwin avatar Feb 22 '18 07:02 andrewgodwin

Thanks a ton

Trying to be a good citizen, I gave a whack at writing a test to POST a file... I don't think I'm doing it quite right. For example, I'm not testing whether the fake PDF is received at all, I see a .send() but no .receive()

EDIT: Found event['body'] and added assertion to check that

ckcollab avatar Feb 22 '18 08:02 ckcollab

That looks about right to me - does the test pass?

andrewgodwin avatar Feb 23 '18 01:02 andrewgodwin

Yeah the test passes, unfortunately. I may need to make more of an integration test to get a failure?

ckcollab avatar Feb 23 '18 01:02 ckcollab

It may be a problem in Daphne rather than Channels, then, as that's the thing not being tested. I'll be able to get to looking at that by the weekend I would hope.

andrewgodwin avatar Feb 23 '18 05:02 andrewgodwin

@andrewgodwin any update on this issue?

Rubyj avatar May 29 '19 15:05 Rubyj

Currently experienced same issue with:

channels==2.1.7
channels-redis==2.3.3
Django==2.1.4
django-cors-headers==2.4.0
django-filter==2.1.0
django-model-utils==3.1.2
django-nose==1.4.6
djangorestframework==3.9.0
djangorestframework-simplejwt==3.3
djangorestframework-stubs==0.2.0

File loaded successfully but server freezesserver messege: Application instance <Task pending coro=<AsgiHandler.__call__() running at /home/oprimov/v_envs/sentry_env/lib/python3.6/site-packages/channels/http.py:213> wait_for=<Future pending cb=[_chain_future.<locals>._call_check_cancel() at /usr/lib/python3.6/asyncio/futures.py:403, <TaskWakeupMethWrapper object at 0x7f4ffffe89d8>()]>> for connection <WebRequest at 0x7f4fff7a8358 method=POST uri=/admin/tasks/task/1/change/ clientproto=HTTP/1.1> took too long to shut down and was killed.

@andrewgodwin any update on this issue? workarounds?

fupydev avatar Oct 28 '19 12:10 fupydev

Currently experienced same issue with:

channels==2.1.7
channels-redis==2.3.3
Django==2.1.4
django-cors-headers==2.4.0
django-filter==2.1.0
django-model-utils==3.1.2
django-nose==1.4.6
djangorestframework==3.9.0
djangorestframework-simplejwt==3.3
djangorestframework-stubs==0.2.0

File loaded successfully but server freezesserver messege: Application instance <Task pending coro=<AsgiHandler.__call__() running at /home/oprimov/v_envs/sentry_env/lib/python3.6/site-packages/channels/http.py:213> wait_for=<Future pending cb=[_chain_future.<locals>._call_check_cancel() at /usr/lib/python3.6/asyncio/futures.py:403, <TaskWakeupMethWrapper object at 0x7f4ffffe89d8>()]>> for connection <WebRequest at 0x7f4fff7a8358 method=POST uri=/admin/tasks/task/1/change/ clientproto=HTTP/1.1> took too long to shut down and was killed.

@andrewgodwin any update on this issue? workarounds?

@fupydev , did you manage to fix this problem?

ThreshHNS avatar Nov 16 '20 14:11 ThreshHNS

Currently experienced same issue with:

channels==2.1.7
channels-redis==2.3.3
Django==2.1.4
django-cors-headers==2.4.0
django-filter==2.1.0
django-model-utils==3.1.2
django-nose==1.4.6
djangorestframework==3.9.0
djangorestframework-simplejwt==3.3
djangorestframework-stubs==0.2.0

File loaded successfully but server freezesserver messege: Application instance <Task pending coro=<AsgiHandler.__call__() running at /home/oprimov/v_envs/sentry_env/lib/python3.6/site-packages/channels/http.py:213> wait_for=<Future pending cb=[_chain_future.<locals>._call_check_cancel() at /usr/lib/python3.6/asyncio/futures.py:403, <TaskWakeupMethWrapper object at 0x7f4ffffe89d8>()]>> for connection <WebRequest at 0x7f4fff7a8358 method=POST uri=/admin/tasks/task/1/change/ clientproto=HTTP/1.1> took too long to shut down and was killed. @andrewgodwin any update on this issue? workarounds?

@fupydev , did you manage to fix this problem?

@ThreshHNS no, at that time just I found this (but not checked it): https://stackoverflow.com/questions/56049194/error-handling-post-request-in-django-and-getting-too-long-to-shutdown-and-was

fupydev avatar Nov 16 '20 17:11 fupydev