question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

force:apex:execute hangs for 60s and returns status 0 when it fails

See original GitHub issue

Summary

When you run force:apex:execute and enter the Apex code in STDIN, the CLI hangs for 60 seconds even though the request is already completed and the result is present in STDOUT

And if the entered Apex code does not compile or throws an Exception, the CLI returns status 0

Steps To Reproduce:

Valid Apex code (hangs for 60s):

sfdx force:apex:execute -u dev22483 <<< "System.debug('hello forcedotcom/cli!');"

Invalid Apex code (hangs for 60s and returns 0):

sfdx force:apex:execute -u dev22483 <<< "invalid apex code"

Apex code that throws exception (hangs for 60s and returns 0):

sfdx force:apex:execute -u dev22483 <<< "throw new IllegalArgumentException();"

It even returns 0 if a governor limit is reached:

sfdx force:apex:execute -u dev22483 <<< "for (Integer i = 0; i < 101; i++) Object queryResult = [SELECT Id FROM Product2 LIMIT 1];"

Expected result

  • The CLI should return the result as soon as the anonymous apex code block is executed
  • The CLI should not return status 0 if the anonymous apex code block does not compile
  • The CLI should not return status 0 if the anonymous apex code block throws an exception
  • The CLI should not return status 0 if the anonymous apex code block throws an uncatchable exception (governor limit reached)

Actual result

The CLI is always hanging for 60s even though the execution was completed and is always returning status 0 for compile errors and exceptions.

Additional information

Extra:

If using the --json flag, although the command still hangs for 60s and returns 0, I can see that the json result contains the success and compiled fields, so with jq we can override the CLI behavior and return non-zero until this is resolved:

image

SFDX CLI Version:

sfdx-cli/7.89.2 darwin-x64 node-v15.5.1

SFDX plugin Versions:

@oclif/plugin-autocomplete 0.3.0 (core)
@oclif/plugin-commands 1.3.0 (core)
@oclif/plugin-help 3.2.2 (core)
@oclif/plugin-not-found 1.2.4 (core)
@oclif/plugin-plugins 1.10.0 (core)
@oclif/plugin-update 1.4.0-2 (core)
@oclif/plugin-warn-if-update-available 1.7.0 (core)
@oclif/plugin-which 1.0.3 (core)
@salesforce/sfdx-diff 0.0.6
@salesforce/sfdx-trust 3.6.0 (core)
alias 1.1.7 (core)
auth 1.4.10
config 1.2.5 (core)
evergreen 0.34.0
└─ evergreen-build 0.20.2
generator 1.1.5 (core)
salesforcedx 51.1.1 (core)
├─ limits 1.0.4 (core)
├─ user 1.1.2 (core)
├─ custom-metadata 1.0.11 (core)
├─ schema 1.0.4 (core)
├─ templates 51.3.0 (core)
├─ apex 0.1.4 (core)
├─ @salesforce/sfdx-plugin-lwc-test 0.1.7 (core)
└─ salesforce-alm 51.1.1 (core)
sfdmu 3.10.0
sfdx-cli 7.89.2 (core)
telemetry 1.1.1 (core)

OS and version: macOS Catalina 10.15.7

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
MuriloKakazucommented, Mar 29, 2021

@mshanemc just to clarify: is this really an apex issue? 🤔 Pardon my ignorance because I also don’t know if the CLI code is owned by multiple teams or not, but from what I could see from this issue the code already compiled, executed and the result was returned and presented in stdout, but the CLI is still hanged after that.

The problem apparently relies in the CLI itself and not in Apex or an API, The CLI always hangs for exactly 60 seconds, even though the API request was processed and the result returned.

0reactions
github-actions[bot]commented, Mar 26, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

sfdx force:apex:execute does not exit after completion ... - GitHub
Run sfdx force:apex:execute , type a line and hit CTRL-D to trigger execution ... Anonymous code executes (or returns an error) and hangs, ......
Read more >
How to return exit code 0 from a failed command
Simply append return 0 to the function to force a function to always exit successful. function a() { ls aaaaa 2>&1 return 0...
Read more >
Free Salesforce Platform developer I Practice Exam
Try our 60 question practice exam to see if you are ready to take on the real exam. Professionally written questions by Salesforce...
Read more >
Mastering Salesforce DevOps : A Practical Guide to Building ...
This practical guide brings DevOps principles to Salesforce development. It fits together two major movements within the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found