Closed btamburrino closed 1 year ago
One of my colleagues on Mac verified that this bug occurs for them as well with the latest sfdx, so it is sadly not a Windows-only issue.
The root cause is because of the new timeout in module @salesforce/apex-node
executeService.js
. In getUserInput()
there is a timeout of 60 seconds on the readInterface
. This timeout is not closed when the readInterface
sends a close event, so the awaiter is waiting for the timeout to complete.
If you add timeout.close();
after resole(apexCode);
then the bug reported here goes away. This timeout did not exist in the original implementation that was in salesforce-alm
hence why it was not an issue before
// apex-node/../executeService.js getUserInput()
readInterface.on('close', () => {
resolve(apexCode);
timeout.close(); // add me!
});
A workaround is to write to an intermediate file:
echo "System.debug('Hello');" > throwaway.apex
sfdx force:apex:execute -f throwaway.apex
This was fixed a few years ago in apex-node: https://github.com/forcedotcom/salesforcedx-apex/blob/c986abfabee3edf12f396f1d2e43720988fa3911/src/execute/executeService.ts#L97
Summary
We have a script that runs multiple generated Apex lines and pipes them through
sfdx force:apex:execute
. This has, historically, worked beautifully, however today when I revisited those scripts, they no longer exit out of sfdx after completing successfully, which blocks the rest of our script execution.Steps To Reproduce:
Two ways:
echo "System.debug('Hello');" | sfdx force:apex:execute
OR
sfdx force:apex:execute
, type a line and hit CTRL-D to trigger executionExpected result
Anonymous code executes (or returns an error) and then exits back to the command line
Actual result
Anonymous code executes (or returns an error) and hangs, requiring the user to hit CTRL-C to
Terminate batch job (Y/N)?
- which then terminates the calling shell script that had been blocked.EDIT Part of this is impatience. It DOES finally exit out after about a minute, however before it was virtually instantaneous.
Additional information
SFDX CLI Version sfdx-cli/7.75.1-5585088c75 win32-x64 node-v12.18.3
SFDX plugin Version
OS and version: Windows 10, using primarily Git Bash in Visual Studio Code's Terminal window, but also occurs in normal Command Prompt