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

Crash when connecting the socket #1033

Open
gouravkmar opened this issue Jun 14, 2024 · 11 comments
Open

Crash when connecting the socket #1033

gouravkmar opened this issue Jun 14, 2024 · 11 comments
Labels

Comments

@gouravkmar
Copy link

gouravkmar commented Jun 14, 2024

Since we upgraded to 4.0.8 version, we have noticed a crash in didReceive(event: WebSocketEvent) method after calling the connect() method
Below is the screenshot of the crash , it occurs shortly after calling socket's connect() method.

Screenshot 2024-06-14 at 2 36 49 PM

socket initialisation is as below:-
` var request = URLRequest(url: URL(string: "wss://(sSocketServerHostName)")!)
request.timeoutInterval = 30

    let cookies = HTTPCookie.requestHeaderFields(with: HTTPCookieStorage.shared.cookies(for: URL(string: sApiServerHostName)!) ?? [])
    let keys = cookies.keys
    for key in keys{
        request.setValue(cookies[key], forHTTPHeaderField: key)
    }
    request.setValue("websocket", forHTTPHeaderField: "Upgrade")
    request.setValue("\(sSocketServerHostName)", forHTTPHeaderField: "Host")
    request.setValue("\(sApiServerHostName)", forHTTPHeaderField: "Origin")
    request.setValue("13", forHTTPHeaderField: "Sec-WebSocket-Version")
    request.setValue("Upgrade", forHTTPHeaderField: "connection")
    socket = WebSocket(request: request)
    socket?.delegate = self
    socket?.connect()`

Environment:

  • OS/Version: [e.g. iOS/17.0]
  • Starscream Version [e.g. 4.0.8]
  • Xcode version [e.g. 15.0.1]

Additional context

Add any other context about the problem here.

@CodeKunal
Copy link

@daltoniam please help here.

@Charlotte3240
Copy link

update to xcode 15.3 or xcode 15.4 try it again

@DeepBhupatkar
Copy link

Hello, did you manage to resolve the issue? I am encountering the same difficulty. Do you have any suggestions for a solution?

@make1a
Copy link

make1a commented Aug 28, 2024

I am still facing the same issue. Do you have any suggestions for a solution?

@Charlotte3240
Copy link

I am still facing the same issue. Do you have any suggestions for a solution?

on Websocket.swift file change this code

    public convenience init(request: URLRequest, certPinner: CertificatePinning? = FoundationSecurity(), compressionHandler: CompressionHandler? = nil, useCustomEngine: Bool = true) {
        if #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *), !useCustomEngine {
            self.init(request: request, engine: NativeEngine())
        } 
//        else if #available(macOS 10.14, iOS 12.0, watchOS 5.0, tvOS 12.0, *) {
//            self.init(request: request, engine: WSEngine(transport: TCPTransport(), certPinner: certPinner, compressionHandler: compressionHandler))
//        } 
        else {
            self.init(request: request, engine: WSEngine(transport: FoundationTransport(), certPinner: certPinner, compressionHandler: compressionHandler))
        }
    }

@DeepBhupatkar
Copy link

DeepBhupatkar commented Aug 28, 2024

I am still facing the same issue. Do you have any suggestions for a solution?

on Websocket.swift file change this code

    public convenience init(request: URLRequest, certPinner: CertificatePinning? = FoundationSecurity(), compressionHandler: CompressionHandler? = nil, useCustomEngine: Bool = true) {
        if #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *), !useCustomEngine {
            self.init(request: request, engine: NativeEngine())
        } 
//        else if #available(macOS 10.14, iOS 12.0, watchOS 5.0, tvOS 12.0, *) {
//            self.init(request: request, engine: WSEngine(transport: TCPTransport(), certPinner: certPinner, compressionHandler: compressionHandler))
//        } 
        else {
            self.init(request: request, engine: WSEngine(transport: FoundationTransport(), certPinner: certPinner, compressionHandler: compressionHandler))
        }
    }

can you describe what will this code do ? i am also facing the crash. and i am only dependent on starScream i am not using native socket by apple.

@Charlotte3240
Copy link

I am still facing the same issue. Do you have any suggestions for a solution?

on Websocket.swift file change this code

    public convenience init(request: URLRequest, certPinner: CertificatePinning? = FoundationSecurity(), compressionHandler: CompressionHandler? = nil, useCustomEngine: Bool = true) {
        if #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *), !useCustomEngine {
            self.init(request: request, engine: NativeEngine())
        } 
//        else if #available(macOS 10.14, iOS 12.0, watchOS 5.0, tvOS 12.0, *) {
//            self.init(request: request, engine: WSEngine(transport: TCPTransport(), certPinner: certPinner, compressionHandler: compressionHandler))
//        } 
        else {
            self.init(request: request, engine: WSEngine(transport: FoundationTransport(), certPinner: certPinner, compressionHandler: compressionHandler))
        }
    }

can you describe what will this code do ? i am also facing the crash.

this code for don't use network.framework to transport , iOS 13.0 - use foundation transport

@Charlotte3240
Copy link

I am still facing the same issue. Do you have any suggestions for a solution?

on Websocket.swift file change this code

    public convenience init(request: URLRequest, certPinner: CertificatePinning? = FoundationSecurity(), compressionHandler: CompressionHandler? = nil, useCustomEngine: Bool = true) {
        if #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *), !useCustomEngine {
            self.init(request: request, engine: NativeEngine())
        } 
//        else if #available(macOS 10.14, iOS 12.0, watchOS 5.0, tvOS 12.0, *) {
//            self.init(request: request, engine: WSEngine(transport: TCPTransport(), certPinner: certPinner, compressionHandler: compressionHandler))
//        } 
        else {
            self.init(request: request, engine: WSEngine(transport: FoundationTransport(), certPinner: certPinner, compressionHandler: compressionHandler))
        }
    }

can you describe what will this code do ? i am also facing the crash. and i am only dependent on starScream i am not using native socket by apple.

I understand , your crash for the reconnect scene?

you can connect after disconnect 0.5 second

@DeepBhupatkar
Copy link

I am still facing the same issue. Do you have any suggestions for a solution?

on Websocket.swift file change this code

    public convenience init(request: URLRequest, certPinner: CertificatePinning? = FoundationSecurity(), compressionHandler: CompressionHandler? = nil, useCustomEngine: Bool = true) {
        if #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *), !useCustomEngine {
            self.init(request: request, engine: NativeEngine())
        } 
//        else if #available(macOS 10.14, iOS 12.0, watchOS 5.0, tvOS 12.0, *) {
//            self.init(request: request, engine: WSEngine(transport: TCPTransport(), certPinner: certPinner, compressionHandler: compressionHandler))
//        } 
        else {
            self.init(request: request, engine: WSEngine(transport: FoundationTransport(), certPinner: certPinner, compressionHandler: compressionHandler))
        }
    }

can you describe what will this code do ? i am also facing the crash. and i am only dependent on starScream i am not using native socket by apple.

I understand , your crash for the reconnect scene?
you can connect after disconnect 0.5 second

The app is crashing randomly, even though it worked fine when I first ran it on two devices. I've been repeatedly closing and joining the meeting (it's an audio-video calling app), and within milliseconds, it keeps crashing. Sometimes, this happens after 4-5 attempts. However, after a crash, if I try again within 3-4 seconds, it works fine. I have no idea how to resolve this issue or what exactly is happening

@Charlotte3240
Copy link

there has two problem

  1. you should use show your code (fountion transport)
  2. delay some time(e.g. 0.5 or 1 second) reconnect websocket when disconnect and you must be sure disconnected

@DeepBhupatkar
Copy link

there has two problem

  1. you should use show your code (fountion transport)
  2. delay some time(e.g. 0.5 or 1 second) reconnect websocket when disconnect and you must be sure disconnected

Sure i will try to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants