     }
 
     fileprivate func generateRequestId() -> Int {
-        self.currRequestId += 1
+        // for thread safety this should only be called from the requestQueue
+        self.currRequestId = self.currRequestId + 1
         return self.currRequestId
     }
 }

    fileprivate var serializer: SwampSerializer?
    fileprivate var sessionId: Int?
    fileprivate var routerSupportedRoles: [SwampRole]?

    // MARK: Call role
    //                         requestId

    internal let subscription: Int
    internal let eventCallback: EventCallback
    fileprivate var isActive: Bool = true
    
    internal init(session: SwampSession, subscription: Int, onEvent: @escaping EventCallback) {
        self.session = session
        self.subscription = subscription
