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

ValueError: Invalid file descriptor: -1 #51

Closed
rsking01 opened this issue Apr 11, 2023 · 2 comments
Closed

ValueError: Invalid file descriptor: -1 #51

rsking01 opened this issue Apr 11, 2023 · 2 comments
Labels
question Further information is requested

Comments

@rsking01
Copy link

rsking01 commented Apr 11, 2023

After connecting the websocket, it closes without errors (client side), and in the server log I see this:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/root/server/serverenv/lib/python3.8/site-packages/simple_websocket/ws.py", line 144, in _thread
    sel.register(self.sock, selectors.EVENT_READ, True)
  File "/usr/lib/python3.8/selectors.py", line 352, in register
    key = super().register(fileobj, events, data)
  File "/usr/lib/python3.8/selectors.py", line 238, in register
    key = SelectorKey(fileobj, self._fileobj_lookup(fileobj), events, data)
  File "/usr/lib/python3.8/selectors.py", line 225, in _fileobj_lookup
    return _fileobj_to_fd(fileobj)
  File "/usr/lib/python3.8/selectors.py", line 42, in _fileobj_to_fd
    raise ValueError("Invalid file descriptor: {}".format(fd))
ValueError: Invalid file descriptor: -1

And I don't understand why it happens. My friend is facing this problem, but my client connects to the socket and everything works fine.

Server code:

@sock.route('/index')
@login_required
def index_socket(ws):
	while True:
		data = ws.receive()

		if data == 'test':
			ws.send('test ok')

	ws.close(message = 'bye')

Client Code:

$(document).ready(function() {
	const socket = new WebSocket('wss://' + location.host + '/index');
	
	socket.onopen = function(event) {
		socket.send("test");
	};
	
});
@miguelgrinberg
Copy link
Owner

So let me see if I understand. You have a server that you can connect to just fine, but your friend gets this error? In that case you should look at the browser console and network tabs on your friend's browser to see if there are any clues there.

@miguelgrinberg miguelgrinberg added the question Further information is requested label Apr 11, 2023
@rsking01
Copy link
Author

Hello. It turns out that the problem was that my friend was using the http protocol, and the websocket was using wss. This was due to the fact that I sent the link to the site in the messenger without specifying the protocol (example.com). I'm sorry to bother you, thanks for the reply.

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

No branches or pull requests

2 participants