AndrWeisR
AndrWeisR

Reputation: 1226

Mule Salesforce connection starts failing with INVALID_SESSION_ID

I have a Mule 4.4 app which is connecting to Salesforce using an OAuth JWT connection in Mule, using the latest version 10.19.2 of the Salesforce connector. I am connecting to a connected app in Salesforce which has OAuth enabled. Everything works fine for a period, but after a point the connection always fails with an error received from Salesforce in Mule INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session. I think the timing of the failures coincides with a session expiring in Salesforce (but I'm not sure what kind of session). I have a standard reconnection policy defined in Mule on the Salesforce config.

I would have thought if there was any kind of session expiry, Mule would have refreshed the connection, but that doesn't seem to be happening.

This is my Salesforce config in Mule.

    <salesforce:sfdc-config name="Salesforce_Config_OAuth_JWT" doc:name="Salesforce Config" doc:id="ea2c2201-4942-4024-b45c-d444c50bf382" >
        <salesforce:jwt-connection 
            consumerKey="XXXX" 
            keyStore="XXXX.jks" 
            storePassword="XXXX" 
            principal="XXXX">
            <reconnection >
                <reconnect count="5"/>
            </reconnection>
        </salesforce:jwt-connection>
    </salesforce:sfdc-config>

First I get this warning in the Mule logs:

DEBUG 2024-01-19 09:40:02,328 [[MuleRuntime].uber.02: [salesforcepoc].uber@org.mule.runtime.core.internal.connection.DefaultConnectivityTesterFactory$1.testConnectivity:81 @4531411d] [processor: ; event: ] org.mule.extension.salesforce.internal.connection.provider.ConnectorConfigBuilder: Receiving response from Salesforce. Arguments: {endpoint=https://personal-3d8-dev-ed.develop.my.salesforce.com/services/Soap/u/59.0, response=<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultcode>sf:INVALID_SESSION_ID</faultcode><faultstring>INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session</faultstring><detail><sf:UnexpectedErrorFault xsi:type="sf:UnexpectedErrorFault"><sf:exceptionCode>INVALID_SESSION_ID</sf:exceptionCode><sf:exceptionMessage>Invalid Session ID found in SessionHeader: Illegal Session</sf:exceptionMessage></sf:UnexpectedErrorFault></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>}.
WARN  2024-01-19 09:40:02,337 [[MuleRuntime].uber.02: [salesforcepoc].uber@org.mule.runtime.core.internal.connection.DefaultConnectivityTesterFactory$1.testConnectivity:81 @4531411d] [processor: ; event: ] org.mule.extension.salesforce.internal.connection.provider.AbstractConnectionProvider: Couldn't validate the connection because an exception occurred. Please check credentials. Root exception was: org.mule.runtime.api.connection.ConnectionException: null
Caused by: org.mule.runtime.api.connection.ConnectionException: null
Caused by: [UnexpectedErrorFault [ApiFault  exceptionCode='INVALID_SESSION_ID'
 exceptionMessage='Invalid Session ID found in SessionHeader: Illegal Session'
 extendedErrorDetails='{[0]}'
]
]

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

Then following that, I get errors:

DEBUG 2024-01-19 09:40:03,164 [HttpClient@bcf806b-123] [processor: ; event: ] org.mule.extension.salesforce.internal.service.streaming.transport.CustomJettyHttpClientTransport: Received messages. Arguments: {messages=[{ext={sfdc={failureReason=401::Authentication invalid}, replay=true, payload.format=true}, advice={reconnect=none}, channel=/meta/handshake, id=1, error=403::Handshake denied, successful=false}], total=1}.
DEBUG 2024-01-19 09:40:03,164 [HttpClient@7d037e76-122] [processor: ; event: ] org.mule.extension.salesforce.internal.service.streaming.transport.CustomJettyHttpClientTransport: Received messages. Arguments: {messages=[{ext={sfdc={failureReason=401::Authentication invalid}, replay=true, payload.format=true}, advice={reconnect=none}, channel=/meta/handshake, id=2, error=403::Handshake denied, successful=false}], total=1}.
INFO  2024-01-19 09:40:03,169 [HttpClient@bcf806b-123] [processor: ; event: ] org.mule.extension.salesforce.internal.service.streaming.listeners.AuthFailureListener: A non-successful message has been received. Error handling routine follows. Arguments: {sdfcFailureReason=401::Authentication invalid, instance=https://personal-3d8-dev-ed.develop.my.salesforce.com/cometd/59.0, channel=BayeuxClientChannel@c00433e[/meta/handshake][BayeuxClient@2fd4c303[null][SessionState@6cb2fcbb[HANDSHAKING]]], error=403::Handshake denied, message={ext={sfdc={failureReason=401::Authentication invalid}, replay=true, payload.format=true}, advice={reconnect=none}, channel=/meta/handshake, id=1, error=403::Handshake denied, successful=false}}.
INFO  2024-01-19 09:40:03,169 [HttpClient@7d037e76-122] [processor: ; event: ] org.mule.extension.salesforce.internal.service.streaming.listeners.AuthFailureListener: A non-successful message has been received. Error handling routine follows. Arguments: {sdfcFailureReason=401::Authentication invalid, instance=https://personal-3d8-dev-ed.develop.my.salesforce.com/cometd/59.0, channel=BayeuxClientChannel@11c92d5f[/meta/handshake][BayeuxClient@253d0f57[null][SessionState@4129782e[HANDSHAKING]]], error=403::Handshake denied, message={ext={sfdc={failureReason=401::Authentication invalid}, replay=true, payload.format=true}, advice={reconnect=none}, channel=/meta/handshake, id=2, error=403::Handshake denied, successful=false}}.
WARN  2024-01-19 09:40:03,169 [HttpClient@bcf806b-123] [processor: ; event: ] org.mule.extension.salesforce.internal.service.streaming.listeners.AuthFailureListener: Couldn't connect to Salesforce streaming server because a 401 error has been returned. Reconnecting. Arguments: {sdfcFailureReason=401::Authentication invalid, message={ext={sfdc={failureReason=401::Authentication invalid}, replay=true, payload.format=true}, advice={reconnect=none}, channel=/meta/handshake, id=1, error=403::Handshake denied, successful=false}, error=403::Handshake denied}.
WARN  2024-01-19 09:40:03,169 [HttpClient@7d037e76-122] [processor: ; event: ] org.mule.extension.salesforce.internal.service.streaming.listeners.AuthFailureListener: Couldn't connect to Salesforce streaming server because a 401 error has been returned. Reconnecting. Arguments: {sdfcFailureReason=401::Authentication invalid, message={ext={sfdc={failureReason=401::Authentication invalid}, replay=true, payload.format=true}, advice={reconnect=none}, channel=/meta/handshake, id=2, error=403::Handshake denied, successful=false}, error=403::Handshake denied}.
INFO  2024-01-19 09:40:03,170 [HttpClient@bcf806b-123] [processor: ; event: ] org.mule.extension.salesforce.internal.source.AbstractStreamingSource: The streaming client needs to restart the source. Notifying the runtime. Arguments: {errorMessage=403::Handshake denied, isNewConnectionNeeded=true}.
INFO  2024-01-19 09:40:03,170 [HttpClient@7d037e76-122] [processor: ; event: ] org.mule.extension.salesforce.internal.source.AbstractStreamingSource: The streaming client needs to restart the source. Notifying the runtime. Arguments: {errorMessage=403::Handshake denied, isNewConnectionNeeded=true}.
ERROR 2024-01-19 09:40:03,172 [HttpClient@7d037e76-122] [processor: ; event: ] org.mule.runtime.core.internal.exception.DefaultSystemExceptionStrategy: 
********************************************************************************
Message               : Access Token expired for resource owner id null
Element               : (None)
Element DSL           : (None)
Error type            : (None)
FlowStack             : (None)

  (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

Upvotes: 0

Views: 792

Answers (1)

Rahat Rajdev
Rahat Rajdev

Reputation: 433

Here's a knowledge base article about the "INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session" error with the MuleSoft Salesforce connector. It might be helpful to check it out.

Link: https://help.mulesoft.com/s/article/Salesforce-connector-Error-Invalid-Session-ID-found-in-SessionHeader-Illegal-Session-Session-not-found-missing-session-hash

Upvotes: 0

Related Questions