-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Fix run command race #1470
Fix run command race #1470
Conversation
488adc3
to
0adf9d4
Compare
I'm afraid that the stdin is redirected to /dev/null within drone :( |
@@ -6,13 +6,12 @@ package process | |||
|
|||
import ( | |||
"bytes" | |||
"context" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only availably in 1.7+, we still need to support 1.6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need to support 1.6?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because some developers (@strk for example) still run 1.6. Latest version in Ubuntu 16.04 LTS is 1.6 as well http://packages.ubuntu.com/xenial/golang-go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1349 discussed before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not liking it 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can vendor the package but the reason is less compelling since it doesn't affect end-users. Otherwise we can postpone the PR until Ubuntu catching up with the latest.
By the way, what keeps you (@bkcsoft @strk) using Ubuntu's Go rather than the official one? I'm curious if there's anything I could help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next LTS is 18.04, which should include 1.7+. IMO we should wait for that until droping support for 1.6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I've upgraded already, so don't think about me. Just think about random possible contributor staying safe in her latest debian/ubuntu/fedora stable system. We want to reduce the barriers of entry for any contributor.
We should also have Drone test all Go versions we want to support. For comparison Gogs is Travis-tested against Go versions from 1.5 to master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree that strictly supporting old toolchains would reward the project's developers and users that much, if any. Just speaking for my own opinion though. ❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
18.10 is released and have Go 1.8 so no need for this change.
It's not about reward but entry barrier.
Developers are a scarce resource, and even many of
the documented maintainers are being increasily inactive.
For these reasons I think we should lower the barrier as much
as possible. From low dependencies to documented procedures and
codebase, to easy to use testing frameworks...
|
We could drop Go v1.6 support on Gitea v1.3, so I moved this to v1.3 |
Go v1.6 is already drop in git module so dropped in gitea. https://github.com/go-gitea/git/blob/master/command.go#L9 |
So that we only need to add an implicated declare on some README or other document. |
@bkcsoft need your approval |
modules/process/manager.go
Outdated
if err != nil { | ||
out := fmt.Errorf("exec(%d:%s) failed: %v stdout: %v stderr: %v", pid, desc, err, stdOut, stdErr) | ||
return stdOut.String(), stdErr.String(), out | ||
if err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd change the error-handling to a more go-esque way
if err != nil {
err = fmt.Errorf(...) // NOTE: include the original error as well as the `ctx.Err()`...
}
return stdOut.String(), stdErr.String(), err
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@typeless maybe you could change this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -101,7 +100,10 @@ func (pm *Manager) ExecDirEnv(timeout time.Duration, dir, desc string, env []str | |||
stdOut := new(bytes.Buffer) | |||
stdErr := new(bytes.Buffer) | |||
|
|||
cmd := exec.Command(cmdName, args...) | |||
ctx, cancel := context.WithTimeout(context.Background(), timeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the timeout
is negative? (Since the functions docs says to use -1 for DefaultTimeout
(which we don't seems to honour... )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bkcsoft The first line on this function has checked that. if timeout == -1 timout = 60 *time.Second
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want
if timeout < 0 {
timeout = 60 * time.Second
}
?
LGTM except @bkcsoft 's second comment I agree with. |
LGTM |
And fixing the data races which can be identified by the added tests when -race enabled.
d2400ee
to
b6be1ff
Compare
b6be1ff
to
7dbf2d2
Compare
Codecov Report
@@ Coverage Diff @@
## master #1470 +/- ##
=========================================
+ Coverage 27.05% 27.26% +0.2%
=========================================
Files 89 89
Lines 17650 17640 -10
=========================================
+ Hits 4775 4809 +34
+ Misses 12189 12144 -45
- Partials 686 687 +1
Continue to review full report at Codecov.
|
The following error doesn't seem to be caused by the pull request.
|
Yes it's just random drone failure |
@lafriks that's a network error not caused by this PR. I will test it twice again then I will move it to v1.3.0 and merge it. |
Use exec.CommandContext to simplify timeout handling, and fixing the data races which can be identified by the added tests when -race enabled.
Related to #1453