Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Runner
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlphaChecker
Runner
Commits
205d7878
Commit
205d7878
authored
9 months ago
by
Mihnea Tudor
Browse files
Options
Downloads
Patches
Plain Diff
feat: clean up timeout fix and don't give point on timeout
parent
76cbba86
No related branches found
Branches containing commit
Tags
v1.0.8
Tags containing commit
No related merge requests found
Pipeline
#66362
passed
9 months ago
Stage: release
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cmd/job/main.go
+8
-43
8 additions, 43 deletions
cmd/job/main.go
with
8 additions
and
43 deletions
cmd/job/main.go
+
8
−
43
View file @
205d7878
...
...
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"log/slog"
...
...
@@ -144,16 +145,14 @@ func compareFiles(file1, file2 io.Reader) (bool, error) {
}
func
runProgram
(
input
io
.
Reader
,
output
io
.
Writer
,
reference
io
.
Reader
,
timeout
float64
)
(
test
.
Result
,
error
)
{
if
timeout
<=
0
{
// Set a safety timeout
timeout
=
1
// Set a safety
timeout
if
timeout
<=
0.0
{
timeout
=
5.0
}
timeoutCtx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Duration
(
timeout
*
float64
(
time
.
Second
)))
defer
cancel
()
slog
.
Info
(
"Running a new submission"
,
"timeout"
,
timeout
,
"duration"
,
time
.
Duration
(
timeout
*
float64
(
time
.
Second
)))
cmd
:=
exec
.
CommandContext
(
timeoutCtx
,
"/job/src/app"
)
if
cmd
.
Err
!=
nil
{
return
test
.
NewResultError
(
enums
.
LevelSystem
,
"couldn't create command"
),
cmd
.
Err
...
...
@@ -165,46 +164,12 @@ func runProgram(input io.Reader, output io.Writer, reference io.Reader, timeout
cmd
.
Stdout
=
io
.
MultiWriter
(
output
,
outputCopy
)
cmd
.
Stderr
=
cmd
.
Stdout
cmdReady
:=
make
(
chan
error
)
// ruleaza comanda in paralel
var
err
error
go
func
()
{
tmpErr
:=
cmd
.
Run
()
err
=
tmpErr
cmdReady
<-
tmpErr
}()
timer
:=
time
.
NewTimer
(
time
.
Duration
(
timeout
*
float64
(
time
.
Second
)))
slog
.
Info
(
"Reached select block"
)
select
{
case
<-
cmdReady
:
// anuleaza contextul de intrerupere
cancel
()
slog
.
Info
(
"Job executed successfully"
)
case
<-
timeoutCtx
.
Done
()
:
err
:=
cmd
.
Cancel
()
if
err
!=
nil
{
return
test
.
NewResultError
(
enums
.
LevelSystem
,
"failed to cancel command on timeout"
),
err
}
return
test
.
NewResultError
(
enums
.
LevelUser
,
"time limit exceeded"
),
err
case
<-
timer
.
C
:
err
:=
cmd
.
Cancel
()
if
err
!=
nil
{
return
test
.
NewResultError
(
enums
.
LevelSystem
,
"failed to cancel command on timeout"
),
err
// ruleaza comanda
if
err
:=
cmd
.
Run
();
err
!=
nil
{
if
errors
.
Is
(
err
,
context
.
DeadlineExceeded
)
{
return
test
.
NewResultError
(
enums
.
LevelSystem
,
"time limit exceeded"
),
err
}
return
test
.
NewResultError
(
enums
.
LevelUser
,
"time limit exceeded"
),
err
}
if
err
!=
nil
{
return
test
.
NewResultError
(
enums
.
LevelUser
,
"user program did not finish successfully"
),
err
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment