fregante / GhostText

👻 Use your text editor to write in your browser. Everything you type in the editor will be instantly updated in the browser (and vice versa).
https://GhostText.fregante.com
MIT License
3.33k stars 114 forks source link

Occasional Python error on disconnect #6

Closed fregante closed 10 years ago

fregante commented 10 years ago

Is there a way to disconnect and move to a different textarea? ST console when I close Chrome's tab:

ConnectionResetError: [Errno 54] Connection reset by peer

Chrome's console when I try connecting to a new textarea

Uncaught InvalidStateError: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state. 

Right now the only way to disconnect a work on a new textarea is by closing Sublime. Even disabling+enabling the package is not enough. ST console when I re-enable the package.

OSError: [Errno 48] Address already in use
Cacodaimon commented 10 years ago

This is a known bug, due the simplicity of this "proof of concept".

The WebSocket server runs single threaded which means only one textarea can communicate with SublimeText. By closing the connected textarea's browser tab the server should normally restart and listen for the next connection.

If the socket is still in use and you are using Linux, try a lsof -i :1337 for finding the blocking process.

I'm currently planning a new Version of SublimeTextarea with multi connections support…, you have to be patient until this Version sees the light of day.

fregante commented 10 years ago

It's in use by the package itself, via Sublime's plugin_host

Unfortunately if I close the tab I see that Connection reset by peer error and it won't connect any more.

This is a great proof of concept by the way, I see myself using this all the time. :+1:

fregante commented 10 years ago

I'm not sure where the issue was, I should have pasted the full call stack.

Now it seems to be working:

Setting on message handler
Start
Setting on message handler
Stop
Triggering on_close

Setting on message handler
Start
Setting on message handler
…
fregante commented 10 years ago

I don't know, it happened again, once.

Exception in thread Thread-5:
Traceback (most recent call last):
  File "X/threading.py", line 639, in _bootstrap_inner
  File "X/threading.py", line 596, in run
  File "SublimeTextarea in /Users/bfred/Library/Application Support/Sublime Text 3/Installed Packages/ChromeTextArea.sublime-package", line 64, in web_socket_server_thread
  File "WebSocket.Server in /Users/bfred/Library/Application Support/Sublime Text 3/Installed Packages/ChromeTextArea.sublime-package", line 39, in start
ConnectionResetError: [Errno 54] Connection reset by peer 

I restarted ST and it worked. :frowning:

Cacodaimon commented 10 years ago

Should be resolved with the multi connection support.