Return nil when openFifo returns nil#47
Merged
tonistiigi merged 1 commit intocontainerd:mainfrom Dec 22, 2022
Merged
Conversation
The return statement in the OpenFifo wrapper function implicitly boxes the *fifo pointer into an io.ReadWriteCloser interface value, even when the value is (*fifo)(nil). It is the same gotcha described in https://go.dev/doc/faq#nil_error and causes the same sorts of confusing situations. Modify the OpenFifo wrapper function to return a nil interface value when openFifo returns a nil pointer value. Signed-off-by: Cory Snider <csnider@mirantis.com>
corhere
commented
Nov 8, 2022
|
|
||
| _, err = OpenFifo(context.Background(), filepath.Join(tmpdir, "f0"), syscall.O_RDONLY|syscall.O_NONBLOCK, 0600) | ||
| f, err := OpenFifo(context.Background(), filepath.Join(tmpdir, "f0"), syscall.O_RDONLY|syscall.O_NONBLOCK, 0600) | ||
| assert.Exactly(t, nil, f) |
Member
Author
There was a problem hiding this comment.
Annoyingly, assert.Nil considers non-nil interface values which contain nil concrete values to be nil values despite those values being != nil.
Member
Author
AkihiroSuda
approved these changes
Nov 8, 2022
cpuguy83
approved these changes
Nov 8, 2022
Member
|
Oh! Saw the PR title and had to think of #32, but I see you linked that above, nice 👍 |
thaJeztah
reviewed
Nov 8, 2022
| defer cancel() | ||
|
|
||
| f, err := OpenFifo(ctx, filepath.Join(tmpdir, "f0"), syscall.O_RDONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0600) | ||
| f, err = OpenFifo(ctx, filepath.Join(tmpdir, "f0"), syscall.O_RDONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0600) |
Member
There was a problem hiding this comment.
Oh! Not a blocker (at all), but if you want to reduce code-churn, perhaps reformat the octal values to the new format (0o600) while updating these lines
This was referenced Feb 21, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The return statement in the
OpenFifowrapper function implicitly boxes the*fifopointer into anio.ReadWriteCloserinterface value, even when the value is(*fifo)(nil). It is the same gotcha described in https://go.dev/doc/faq#nil_error and causes the same sorts of confusing situations. Modify theOpenFifowrapper function to return anilinterface value whenopenFiforeturns anilpointer value.(*fifo)(nil)value could escape the package, and therefore the root cause of SIGSEGV dockerd 20.10.2 docker/for-linux#1186 for which fifo.Close(): prevent possible panic if fifo is nil #32 was added as a workaround.