Android. Request interrupted error

Is there any how meet "Request interrupted" error? my you tell what was your reason to get it? i have one request that constantly throws this error on android 7.0 and 7.1
Http logs says, that i call disconnect and send it information to server. and server received it. but i "send disconnect despite on i dont do it. and sometimes i also recieve timeout instead

Comments

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 914 admin

    Hi @VictorKalevich,
    What messaging API are you using? I'm wondering if there is a timeout due to inactivity if the app is goes into the background or something like that.

    @Aaron, I think this might be the timeout situation that you ran into previously?

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 914 admin

    @VictorKalevich - you might also check out this tip that @trishm shared and see if it fixes your issue.

  • VictorKalevich
    VictorKalevich Member Posts: 5

    @marc
    Unfortunately no. this is a common request that works in an unexpected way. the "interrupted request" error is sometimes triggered on other requests and looks like the inability of the library to work asynchronously, for example, if you make the same request twice, this error appears on other requests from time to time. the app is always active during these errors. is there any information I can provide you?

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 914 admin

    Hi @VictorKalevich
    What messaging API are you using?

  • VictorKalevich
    VictorKalevich Member Posts: 5
    edited June 2021 #6

    I apologize for the delay, can u please clarify your request.
    android system
    I m using in app module com.solacesystems:sol-jcsmp:10.9.1
    com.google.protobuf:protobuf-lite:3.0.1
    in protobuf module im using
    implementation 'com.google.protobuf:protobuf-lite:3.0.1'
    protoc {
    artifact = 'com.google.protobuf:protoc:3.9.0'
    }
    javalite {
    artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
    }

  • VictorKalevich
    VictorKalevich Member Posts: 5

    @marc what do u mean saying "What messaging API are you using?"

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 914 admin

    Hey @VictorKalevich, I got the answer from your post above. Since Solace supports our enterprise solace APIs (CCSMP, JCSMP, etc.), MQTT, AMQP & REST I wanted to know which you were using.

    Looks like JCSMP 10.9.1 which is the Solace Java messaging api.
    @VictorKalevich can you maybe share some of the code where you connect/send the requests?

    @Aaron looping you in as you might have an idea here.

  • VictorKalevich
    VictorKalevich Member Posts: 5
    edited July 2021 #9

    @marc

    suspend fun getTradingScreeners(account: SolaceInvestAccount): ProtoFDScreenersRes {
    return withContext(Dispatchers.IO) {
    val payload = ProtoFDScreenersReq.newBuilder()
    .setPayloadType(ProtoFDPayloadType.PROTO_FD_SCREENERS_REQ)
    .build()
    val stringPayload = payload.toByteString()

            val protoMessage = createProtoMessage(
                payloadType = ProtoFDPayloadType.PROTO_FD_SCREENERS_REQ_VALUE,
                payload = stringPayload,
                token = account.credentials
            )
    
            val response = createRequest(message = protoMessage, topicName = account.fundamentals)
    
            val parsedResponse = ProtoFDScreenersRes.parseFrom(response.payload)
    
            parsedResponse
        }
    }
    
    fun createProtoMessage(payloadType: Int, payload: ByteString, token: String): ProtoMessage {
        return ProtoMessage.newBuilder()
            .setClientMsgId(messageId)
            .setPayloadType(payloadType)
            .setPayload(payload)
            .setSessionToken(token)
            .build()
    }
    
    suspend fun createRequest(message: ProtoMessage, topicName: String, operationID: String? = null): ProtoMessage {
        try {
            checkConnectClient()
    
            return withContext(Dispatchers.IO) {
    
                val timeoutMs = 45_000L
                val topic = JCSMPFactory.onlyInstance().createTopic(topicName)
                val senderId = session.getProperty(JCSMPProperties.CLIENT_NAME) as String
    
                val request = prepareSolaceMessage(senderId, message)
                if (!operationID.isNullOrEmpty()) {
                    request.correlationId = operationID
                }
    
                val requestor = session.createRequestor()
                val response = requestor.request(request, timeoutMs, topic)
    
                return@withContext ProtoMessage.parseFrom(response.attachmentByteBuffer.array())
            }
        } catch (ex: Exception) {
    
        }
    }
    
    suspend fun checkConnectClient() {
        mutex.withLock {
            if (isDisconnect) {
                createSession()
            }
        }
    }
    
    private suspend fun createSession() {
        withContext(Dispatchers.IO) {
            session = JCSMPFactory.onlyInstance().createSession(properties)
    
            session.connect()
    
            consumer = session.getMessageConsumer(sessionMessageListener)
            consumer.start()
    
            session.getMessageProducer(sessionStateHandler)
    
            isDisconnect = false
        }
    }
    
    fun updateConfig(solaceConfig: CredentialsJson) {
        solaceConfig.let { credentials ->
            properties.setProperty(JCSMPProperties.HOST, credentials.host)
            properties.setProperty(JCSMPProperties.VPN_NAME, credentials.vpn)
            properties.setProperty(JCSMPProperties.USERNAME, credentials.login)
            properties.setProperty(JCSMPProperties.PASSWORD, credentials.password)
            properties.setProperty(JCSMPProperties.SSL_VALIDATE_CERTIFICATE, false)
        }
    }
    
    private val messageId: String
        get() = UUID.randomUUID().toString()