question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unnecessary access log when socket disconnects before sending any bytes

See original GitHub issue

Describe the bug A socket connection request to server will cause following error:

[2021-08-30 10:29:31 +0800] - (sanic.access)[INFO][UNKNOWN]: NONE http:///*  503 666
[2021-08-30 10:29:31 +0800] [6386] [ERROR] Connection lost before response written @ ('127.0.0.1', 36214) <Request: NONE *>

why and how can i prevent that?

Code snippet server.py

from sanic import Sanic
from sanic import text

app = Sanic.get_app("test", force_create=True)

@app.get("/")
async def response(request):
    return text("ok")

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=9000, access_log=True, debug=True)

client.py

import socket

if __name__ == '__main__':

    server_addr = ('localhost', 9000)

    tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    tcp_socket.connect(server_addr)
    tcp_socket.close()

Expected behavior no error msg

Environment (please complete the following information):

  • OS: CentOS
  • Version: 21.6.2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
Frankr0commented, Dec 29, 2021

Was this fixed? Couldn’t reproduce, or I miss something? image

I just tested it on version 21.12 and it seems to get fixed.

2reactions
ahopkinscommented, Aug 30, 2021

I disagree. A connection is opened, it should be logged. The level at which that happens I do not disagree is probably not an ERROR. But it shouldn’t be quiet either. If for no other reason, it would be very hard to impossible to track what was happening if you had some rogue agent opening and closing connections in rapid succession.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Tcp disconnect detection - Stack Overflow
I have a simpletcp example: import socket import time TCP_IP = '127.0.
Read more >
Question on Socket disconnect handling - Google Groups
I have modified my code to first call Shutdown and wait for zero bytes to be got before calling socket.close. I have a...
Read more >
An Advanced Socket Communication Tutorial
An important characteristic of a datagram socket is that record boundaries in data are preserved. Datagram sockets closely model the facilities found in...
Read more >
Analyzing Disconnects - server - Photon Engine
This is the first check you need to do. All clients have some callback to provide log messages about internal state changes and...
Read more >
26. WebSocket Support - Spring
This part of the reference documentation covers Spring Framework's support for WebSocket-style messaging in web applications including use of STOMP as an ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found