I am running daphne server in production and getting following error
Application instance <Task pending coro=<AsgiHandler.__call__() running at /home/coldbrewtech/frnd/backend/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 0x7f0b49b6a6a8>()]>> for connection <WebRequest at 0x7f0b48daa438 method=POST uri=/api/getMessages clientproto=HTTP/1.1> took too long to shut down and was killed.
It is happening in following POST request:
class GetRoomMessages(APIView):
def post(self, request):
room_no = request.data.get('room_no', None)
message_id = request.data.get('message_id', None)
order = request.data.get('order', None)
message_instance = None
if(order == 'old'):
try:
message_instance = Message.objects.filter(room_no=room_no, id__lt = message_id).order_by('-id')
except Exception as e:
print(e)
return status_500()
elif(order == 'new'):
try:
message_instance = Message.objects.filter(room_no=room_no, id__gt = message_id).order_by('id')
except Exception as e:
print(e)
return status_500()
if(message_instance is not None):
serializer = MessageSerializer(message_instance, many=True)
return status_200("success", serializer.data)
else:
return status_400("Invalid Request")
I am not sure why this is happening, but it happens when there are a lot of messages to serialize. I don't think it is taking time to serialize but rather I think the size of response might be too big. Is that the case in general? If not, can you please tell me what is the reason for same?