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

[Errno 57] Socket is not connected #543

Closed
crypto-sami opened this issue May 14, 2023 · 15 comments · Fixed by #540
Closed

[Errno 57] Socket is not connected #543

crypto-sami opened this issue May 14, 2023 · 15 comments · Fixed by #540
Labels
meta: duplicate This issue or pull request already exists

Comments

@crypto-sami
Copy link

Hello, when I run this piece of code to get the players online, it tells me the number of players online however throws out an error when I query to see which players are online. I have the port forwarding set up correctly and the server is ran on Debian 11 in a docker container.

image image
@PerchunPak
Copy link
Member

Can you provide all commands to reproduce?

@PerchunPak PerchunPak linked a pull request May 14, 2023 that will close this issue
@ItsDrike ItsDrike added meta: Not Enough Information Further clarification is needed area: protocol Related to underlying networking protocol labels May 14, 2023
@PerchunPak
Copy link
Member

PerchunPak commented May 14, 2023

Also, it would be greate if you could try this sample from #538 (comment).

Nevermind, just saw that you use query. Is the status okay? Is the async status and async query okay? Try to run this.

import asyncio
import mcstatus

server = mcstatus.JavaServer.lookup("mc.sturk.au:25565")

async def test():
    try:
        server.status()
    except Exception as exc:
        print(f"Status is not okay: {exc}")
    else:
        print("Status is okay")

    try:
        await server.async_status()
    except Exception as exc:
        print(f"Async status is not okay: {exc}")
    else:
        print("Async status is okay")

    try:
        await server.async_query()
    except Exception as exc:
        print(f"Async query is not okay: {exc}")
    else:
        print("Async query is okay")


if __name__ == "__main__":
    asyncio.run(test())

@crypto-sami
Copy link
Author

hello i ran that and it returned an error, what do you mean all commands to reproduce? as in the whole error message?

File "c:\Users\Sami\Documents\VSCode Projects\python-ssh\main.py", line 4, in
server = mcstatus.lookup("mc.sturk.au:25565")
AttributeError: module 'mcstatus' has no attribute 'lookup'

@PerchunPak
Copy link
Member

Oh, my error. Updated the comment, try again.

what do you mean all commands to reproduce?

How do you run the container?

@crypto-sami
Copy link
Author

i ran it now and it says both status and async status is ok however it said async query is not ok. Its just a paper mc server within a docker container, to run i just run a basic .sh file i set up

@PerchunPak
Copy link
Member

Nevermind, I reproduced it with docker.io/library/python:3.11-slim.

Run mcstatus mc.sturk.au query > log.txt command and send here unedited content of the log.txt file please.

@crypto-sami
Copy link
Author

this is what was put in the log.txt
The server did not respond to the query protocol.
Please ensure that the server has enable-query turned on, and that the necessary port (same as server-port unless query-port is set) is open in any firewall(s).
See https://wiki.vg/Query for further information.

@crypto-sami
Copy link
Author

i run the staff++ plugin, i dont think this should cause any issues. I also only have the port 22565 open on my router settings. I haven't set a certain query port in the server config properties

@kevinkjt2000
Copy link
Contributor

Query must be enabled in server.properties. Additionally, the UDP port for query defaults to 25565, and any firewalls must also allow the UDP traffic.

@ItsDrike
Copy link
Member

Yeah, this is probably just another query isn't enabled or accessible issue, but what surprises me is the error message. I'd expect the error on connection getting established, not on closing.

@kevinkjt2000
Copy link
Contributor

Well the error is that the socket was never connected. The exit methods attempt a losing a socket that was never connected.

@kevinkjt2000
Copy link
Contributor

Closing this as a duplicate of #489

@kevinkjt2000 kevinkjt2000 added meta: duplicate This issue or pull request already exists and removed meta: Not Enough Information Further clarification is needed area: protocol Related to underlying networking protocol labels May 16, 2023
@ItsDrike
Copy link
Member

ItsDrike commented May 16, 2023

Yes, but I wouldn't even expect it to make it past __init__ on the UDPSocketConnection connection, since connection establishing would fail with an exception. It's weird that it's getting into __exit__, and attempting a close in the first place, as that would imply that the connection was somehow established, doesn't it?

async with UDPAsyncSocketConnection(address, self.timeout) as connection:

self.socket = socket.socket(

Although now that I'm thinking of it, UDP connections don't really do any sort of handshake, so I suppose it makes sense.

@PerchunPak
Copy link
Member

Sorry for such delay, just want to mention that I got TimeoutError when tested it. I think, just the screenshot in the head of the issue is not full.

@PerchunPak PerchunPak closed this as not planned Won't fix, can't repro, duplicate, stale May 16, 2023
@ItsDrike
Copy link
Member

Yeah, the screenshot not being complete makes a lot more sense actually, even though UDP would probably indeed let you get past __init__ as there's no initial handshake, during query, you'd still need to actually send/receive traffic, and it's at that moment where the error would absolutely happen. But at that point, you're already within a context manager, and so __exit__ will get ran even if there was an exception, triggering another exception encountered during close.

@PerchunPak PerchunPak closed this as not planned Won't fix, can't repro, duplicate, stale May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta: duplicate This issue or pull request already exists
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants