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

TDA-3417: crash in socket #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions Sources/ApolloWebSocket/DefaultImplementation/WebSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -585,28 +585,31 @@ open class WebSocket: NSObject, WebSocketClient, StreamDelegate, WebSocketStream
/**
Dequeue the incoming input so it is processed in order.
*/
private func dequeueInput() {
while !inputQueue.isEmpty {
autoreleasepool {
let data = inputQueue[0]
var work = data
if let buffer = fragBuffer {
var combine = NSData(data: buffer) as Data
combine.append(data)
work = combine
fragBuffer = nil
}
let buffer = UnsafeRawPointer((work as NSData).bytes).assumingMemoryBound(to: UInt8.self)
let length = work.count
if !connected {
processTCPHandshake(buffer, bufferLen: length)
} else {
processRawMessagesInBuffer(buffer, bufferLen: length)
private func dequeueInput() {
while !inputQueue.isEmpty {
autoreleasepool {
let data = inputQueue[0]
var work = data
if let buffer = fragBuffer {
var combine = buffer
combine.append(data)
work = combine
fragBuffer = nil
}
work.withUnsafeBytes { (buffer: UnsafeRawBufferPointer) in
if let baseAddress = buffer.baseAddress?.assumingMemoryBound(to: UInt8.self) {
let length = work.count
if !connected {
processTCPHandshake(baseAddress, bufferLen: length)
} else {
processRawMessagesInBuffer(baseAddress, bufferLen: length)
}
}
}
inputQueue.removeFirst()
}
}
inputQueue = inputQueue.filter{ $0 != data }
}
}
}

/**
Handle checking the inital connection status
Expand Down