Potentially important qualification: I've been working with Shane McLaughlin to help verify the new org commands, so those were installed when this happened.
Yesterday I ran into a situation where a call to sfdx force:source:push resulted in the following error:
$ sfdx.cmd force:source:push -u [email protected] --json
{
"status": 1,
"name": "Error",
"message": "INVALID_SESSION_ID: Session expired or invalid",
"exitCode": 1,
"commandName": "SourcePushCommand",
"stack": "Error: INVALID_SESSION_ID: Session expired or invalid
at Request._callback (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.89.2-d1d2614d02\\node_modules\\salesforce-alm\\dist\\lib\\core\\force.js:590:29)
at Request.self.callback (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.89.2-d1d2614d02\\node_modules\\request\\request.js:185:22)
at Request.emit (events.js:315:20)
at Request.<anonymous> (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.89.2-d1d2614d02\\node_modules\\request\\request.js:1154:10)
at Request.emit (events.js:315:20)
at IncomingMessage.<anonymous> (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.89.2-d1d2614d02\\node_modules\\request\\request.js:1076:12)
at Object.onceWrapper (events.js:421:28)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)\nOuter stack:
at Function.wrap (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.89.2-d1d2614d02\\node_modules\\@salesforce\\core\\lib\\sfdxError.js:171:27)
at SourcePushCommand.catch (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.89.2-d1d2614d02\\node_modules\\salesforce-alm\\dist\\ToolbeltCommand.js:248:46)
at async SourcePushCommand._run (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.89.2-d1d2614d02\\node_modules\\@salesforce\\command\\lib\\sfdxCommand.js:85:13)
at async Config.runCommand (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.89.2-d1d2614d02\\node_modules\\@oclif\\config\\lib\\config.js:173:24)
at async Main.run (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.89.2-d1d2614d02\\node_modules\\@oclif\\command\\lib\\main.js:27:9)
at async Main._run (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.89.2-d1d2614d02\\node_modules\\@oclif\\command\\lib\\command.js:43:20)
at async Object.run (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.89.2-d1d2614d02\\dist\\cli.js:121:21)",
"warnings": []
}
The immediate next execution of the same command completed without issue. Generally (i.e., with close to 100% consistency) commands refresh the access token if necessary before executing, so it was surprising to see this happen all of a sudden.
I'm happy to provide any additional diagnostic info I can, but given that I've only seen this once, it's going to be difficult to provide steps to reproduce, or even to reproduce it myself locally.
Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.
I think this issue is similar to this issue, https://github.com/forcedotcom/cli/issues/881.
My friend was facing this and we changed the CLI version using below commands taken from the mentioned issue and now it is working fine.
sfdx plugins:install [email protected]
sfdx plugins:install [email protected]
Yeah same issue here... I thought my Scratch Org had expired so I run force:org:list... The scratch was still active and the next push was successful. Seems there's an issue in refreshing the token...
Same here. I get Session expired or invalid on push if I open up my project in VS Code the first time. After opening my current Scratch Org (from vs code), push works again.
I'm not sure but I have been experiencing this since sometime last year. I haven't looked at the code but my understanding is that this was caused by some changes made in response to JWT authentication in CI when the JWT token was taken away after initial authorization. I think the change causes source:push not to be able to get a new token and just try and use the token already available, it is missing the ability to refresh if the current access token is expired.
I don't think this had a specific resolution attached but this was some of the discussion: https://github.com/forcedotcom/cli/issues/81
I think there was another ticket where the resolution was discussed but I can't find it right now.
The REST API does not auto-refresh like it does with SOAP via jsforce. This is a bug and is being tracked internally with W-9016781.
The problem with "Error: INVALID_SESSION_ID: Session expired or invalid" is getting very annoying as it happens with not very long inactivity, and then you need to get the access token refreshed again by for instant using: sfdx force:org:open -u username
This happens several times a day for the same user/org.
Are there changes done to the authentication model that I have not caught?
Most helpful comment
The REST API does not auto-refresh like it does with SOAP via jsforce. This is a bug and is being tracked internally with W-9016781.