websocket: Fix crash in websocket module

- Avoid race condition by maintaining a connection reference count
- Fixes FS#406