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

Fix run command race #1470

Merged
merged 5 commits into from
Nov 13, 2017
Merged

Fix run command race #1470

merged 5 commits into from
Nov 13, 2017

Conversation

typeless
Copy link
Contributor

@typeless typeless commented Apr 8, 2017

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

@typeless typeless changed the title Fix run command race [WIP] Fix run command race Apr 8, 2017
@typeless typeless force-pushed the fix-run-command-race branch from 488adc3 to 0adf9d4 Compare April 8, 2017 08:02
@typeless typeless changed the title [WIP] Fix run command race Fix run command race Apr 8, 2017
@typeless
Copy link
Contributor Author

typeless commented Apr 8, 2017

I'm afraid that the stdin is redirected to /dev/null within drone :(
I would have to think about other approach.

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 8, 2017
@lunny lunny added this to the 1.2.0 milestone Apr 8, 2017
@lunny lunny added the type/bug label Apr 8, 2017
@@ -6,13 +6,12 @@ package process

import (
"bytes"
"context"
Copy link
Member

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

Copy link
Member

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?

Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

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

#1349 discussed before.

Copy link
Member

Choose a reason for hiding this comment

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

Still not liking it 😂

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

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. ❤️

Copy link
Member

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.

@strk
Copy link
Member

strk commented Apr 20, 2017 via email

@lunny lunny modified the milestones: 1.3.0, 1.2.0 May 25, 2017
@lunny
Copy link
Member

lunny commented May 25, 2017

We could drop Go v1.6 support on Gitea v1.3, so I moved this to v1.3

@sapk
Copy link
Member

sapk commented May 26, 2017

Go v1.6 is already drop in git module so dropped in gitea. https://github.com/go-gitea/git/blob/master/command.go#L9

@lunny
Copy link
Member

lunny commented May 26, 2017

So that we only need to add an implicated declare on some README or other document.

@lafriks
Copy link
Member

lafriks commented Oct 25, 2017

@bkcsoft need your approval

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 {
Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Member

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... )

Copy link
Member

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

Copy link
Contributor Author

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
}

?

@lunny
Copy link
Member

lunny commented Nov 7, 2017

LGTM except @bkcsoft 's second comment I agree with.

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Nov 7, 2017
@lunny lunny modified the milestones: 1.3.0, 1.4.0 Nov 10, 2017
@bkcsoft
Copy link
Member

bkcsoft commented Nov 13, 2017

LGTM

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Nov 13, 2017
And fixing the data races which can be identified by the added tests when -race enabled.
@typeless typeless force-pushed the fix-run-command-race branch from d2400ee to b6be1ff Compare November 13, 2017 07:37
@typeless typeless force-pushed the fix-run-command-race branch from b6be1ff to 7dbf2d2 Compare November 13, 2017 08:44
@codecov-io
Copy link

codecov-io commented Nov 13, 2017

Codecov Report

Merging #1470 into master will increase coverage by 0.2%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
modules/process/manager.go 73.91% <100%> (+52.39%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e9728bf...41a01f0. Read the comment docs.

@typeless
Copy link
Contributor Author

The following error doesn't seem to be caused by the pull request.

fatal: unable to access 'https://go.googlesource.com/tools/': Failed to connect to go.googlesource.com port 443: Operation timed out
128s

@lafriks
Copy link
Member

lafriks commented Nov 13, 2017

Yes it's just random drone failure

@lunny
Copy link
Member

lunny commented Nov 13, 2017

@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.

@lunny lunny modified the milestones: 1.4.0, 1.3.0 Nov 13, 2017
@lunny lunny merged commit f4d12f8 into go-gitea:master Nov 13, 2017
@lunny lunny mentioned this pull request Nov 13, 2017
7 tasks
@typeless typeless deleted the fix-run-command-race branch April 3, 2019 05:01
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants