Error: INVALID_SESSION_ID
Context
I was trying to create a connection manager for a cloud function. Since it's estimated that the function will be will be invoked in a very low frequency (e.g. few times in a day) so keeping a connection alive did not seems to be worthwhile. When I use the following wrapper to ensure that connections are always properly closed, the error came up.
const jsforce = require('jsforce')
const exec = async (fn) => {
debug('connecting')
const conn = new jsforce.Connection({
loginUrl: process.env.SALESFORCE_URL
})
await conn.login(process.env.SALESFORCE_USERNAME, process.env.SALESFORCE_PASSWORD)
try {
await fn(conn)
} catch (e) {
reportError(e)
} finally {
debug('disconnecting')
conn.logout().catch(reportError)
}
}
Error message.
Error: INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session.
Session not found, missing session hash: <redacted>.
This error usually occurs after a session expires or a user logs out.
Maybe it's answered in #210, but what's the best practice for managing connection in a long-running process?
- Globally shared singleton.
- Reconnect every time.
- Connection pool.
Environments:
- Node.js v10 (Google Cloud Functions)
- jsforce v1.9.1
Make sure process.env.SALESFORCE_PASSWORD has your security token appended to it?
Late to the party but +1 to this question. (Also I'm aware that one needs to append the security token.)
@hden did you ever figure out a practice that works well?
No, but I found a Japanese article suggesting that a global shared singleton should be used.
https://kikutaro777.hatenablog.com/entry/2016/03/19/232116
Thanks @hden! :)