Https (wss) error on connection
- Dominant language
- PHP
- Stars
- 11.6k
- Forks
- 2.2k
- Avg merge
- 11h 30m
- Merged PRs (30d)
- 3
Description
Hello. I have been struggling to launch a project on https for a long time. Using the http option and using the server's IP, everything works.
I have a subdomain like psql.site.ru
I start the worker using the code:
```
$context = array(
'ssl' => array(
'local_cert' => storage_path('app/certs/fullchain1.pem'), // cert
'local_pk' => storage_path('app/certs/privkey1.pem'), // key
'verify_peer' => false,
)
);
$ws_worker = new Worker('websocket://psql.site.ru, $context);
$ws_worker->transport = 'ssl';
$ws_worker->count = 1;
.........
```
The certificate files are valid and their paths are correct. Rights exhibited 666
On the frontend side connect:
```
let ws = new WebSocket("wss://psql.site.ru/?token={{ $token }}");
ws.onmessage = function (evt) {
console .log(evt);
}
document.getElementById('btn').addEventListener('click', function(t) {
let data = {
"event": "SEND_MESSAGE"
};
ws.send(JSON.stringify(data))
});
```
When i connect, i get an error:
`
WebSocket connection to 'wss://psql.site.ru:2346/?token=123' failed:
`
And i get an error in "onerror" event:
```
Event {isTrusted: true, type: 'error', target: WebSocket, currentTarget: WebSocket, eventPhase: 2, …}
isTrusted: true
bubbles: false
cancelBubble: false
cancelable: false
composed: false
currentTarget: WebSocket {url: 'wss://psql.site.ru:2346/?token=123', readyState: 3, bufferedAmount: 0, onopen: ƒ, onerror: ƒ, …}
defaultPrevented: false
eventPhase: 0
returnValue: true
srcElement: WebSocket {url: 'wss://psql.site.ru:2346/?token=123', readyState: 3, bufferedAmount: 0, onopen: ƒ, onerror: ƒ, …}
target: WebSocket {url: 'wss://psql.site.ru:2346/?token=123', readyState: 3, bufferedAmount: 0, onopen: ƒ, onerror: ƒ, …}
timeStamp: 448.7000000476837
type: "error"
```
And i get error in "onclose":
```
CloseEvent {isTrusted: true, wasClean: false, code: 1006, reason: '', type: 'close', …}
isTrusted: true
bubbles: false
cancelBubble: false
cancelable: false
code: 1006
composed: false
currentTarget: WebSocket {url: 'wss://psql.site.ru:2346/?token=123', readyState: 3, bufferedAmount: 0, onopen: ƒ, onerror: ƒ, …}
defaultPrevented: false
eventPhase: 0
reason: ""
returnValue: true
srcElement: WebSocket {url: 'wss://psql.site.ru:2346/?token=123', readyState: 3, bufferedAmount: 0, onopen: ƒ, onerror: ƒ, …}
target: WebSocket {url: 'wss://psql.site.ru:2346/?token=123', readyState: 3, bufferedAmount: 0, onopen: ƒ, onerror: ƒ, …}
timeStamp: 449.60000002384186
type: "close"
wasClean: false
```
I use standard ports 2346 for connection. But when I change the ports to others (for example, 2246), the error does not immediately occur. It occurs when I try to send something to the server. I get an error like:
`
Uncaught DOMException: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.
`
Help please, can this error be due to the fact that the subdomain is used? Or was the certificate issued via lets encrypt ?
I will be very grateful, I have been trying to solve the problem for several days
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the Worker SSL setup and frontend WebSocket URL shown in the issue, including the certificate paths, transport, and ports. Reproduce the connection failure and inspect the server and browser connection results for the WSS endpoint. Done means the documented setup establishes a WebSocket connection and can send a message successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100