Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle unsigned int errorcodes more gracefully in Windows Batch #232

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

StefanSpieker
Copy link
Contributor

We have a job on a Windows machine which executes a Matlab project within a batch-file, and has actually a quite high error code of 3221225477. We are using the binary wrapper, and so this quite high number gets written into the text file. The parsing fails with an IOException and the connection gets lost to the agent. I was first confused, but actually windows uses an unsigned int for the error codes, as documented here. I decided to set it to max integer, which is from my point of view better than throwing the exception, but I added a warning log message about it.

Testing done

Added a unit test which reproduces the error and verifies that it is resolved like this.

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@StefanSpieker StefanSpieker requested a review from a team as a code owner September 13, 2024 15:52
Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FTR

* @return an exit code (zero is successful), or null if the task appears to still be running
*/
public @CheckForNull Integer exitStatus(FilePath workspace, Launcher launcher, TaskListener logger) throws IOException, InterruptedException {
if (Util.isOverridden(Controller.class, getClass(), "exitStatus", FilePath.class, Launcher.class)) {
would ideally be expanded to Long but that would require changes also to https://github.com/jenkinsci/workflow-durable-task-step-plugin/blob/b7cec8f3b95e9807f78706346641fd9e41ff4039/src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/DurableTaskStep.java#L655 etc., which feels like overkill.

Comment on lines +122 to +126
if (enableBinary) {
assertEquals(Integer.valueOf(Integer.MAX_VALUE), c.exitStatus(ws, launcher, listener));
} else {
assertEquals(Integer.valueOf(-1073741819), c.exitStatus(ws, launcher, listener));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the difference between https://github.com/jenkinsci/lib-durable-task/blob/c823f6cb78f5208589b41e5ba467635b5ea121c1/src/pkg/common/common.go#L151-L157 vs.

cmdString = String.format("@echo off \r\ncmd /c call \"%s\" > \"%s\" 2>&1\r\necho %%ERRORLEVEL%% > \"%s\"\r\n",
? Not great there is this inconsistency, though I suppose it is unlikely to matter much in practice (either way it is a failure).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes, so windows is always using unsigned int to return error codes? If so, I think lib-durable needs to be updated

@jglick jglick added the bug label Sep 13, 2024
@jglick jglick merged commit 2a8a4b7 into jenkinsci:master Sep 13, 2024
16 checks passed
@StefanSpieker StefanSpieker deleted the unsignedInt branch September 13, 2024 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants