`try await URLSessionWebSocketTask.send()` does not return nor throw

I want to send multiple messages to a web socket like this:

let session = URLSession(configuration: .default)
var socket = session.webSocketTask(with: URLRequest(url: self.url, timeoutInterval: 30)
socket.resume()

do {
	for message in messages {
		try await socket.send(message)
	}
} catch {
	print(error)
}

Sometimes all messages are sent, but most times the 10th messages simply does not finish nor fail. I even added delegate methods to detect if the socket is closed or if something failed, but those delegate methods never get called. The send simply does not return nor throw. I thought that adding the timeoutInterval would cause the send to fail if it didn’t succeed after 30 seconds, but that does not seem to be the case.

Has anyone an idea what could be happening here and how I can resolve this? Any help is greatly appreciated, thanks in advance.

PS: the message it failed on mostly is only about 79 Bytes, so it should not take that long to send, especially since sending far longer messages works just fine

EDIT: I just tried to use the synchronous version of send with the completionHandler as I hoped that maybe the async version might be bugged, but I have the same problem using that, no completion handler is called

I found following message in the console: Connection 1: received failure notification. Is there a way to detect this? No delegate method is called, neither in URLSessionTaskDelegate nor in URLSessionDelegate

Maybe you detected it in:

} catch {
	print(error)
}

Try putting a breakpoint in print and see if that console output came from that print. Or put your own text in front of that error. If yes, that is The Way to detect that.

`try await URLSessionWebSocketTask.send()` does not return nor throw
 
 
Q