Giter Site home page Giter Site logo

fifo's Introduction

fifo

PkgGoDev Build Status codecov Go Report Card

Go package for handling fifos in a sane way.

// OpenFifo opens a fifo. Returns io.ReadWriteCloser.
// Context can be used to cancel this function until open(2) has not returned.
// Accepted flags:
// - syscall.O_CREAT - create new fifo if one doesn't exist
// - syscall.O_RDONLY - open fifo only from reader side
// - syscall.O_WRONLY - open fifo only from writer side
// - syscall.O_RDWR - open fifo from both sides, never block on syscall level
// - syscall.O_NONBLOCK - return io.ReadWriteCloser even if other side of the
//     fifo isn't open. read/write will be connected after the actual fifo is
//     open or after fifo is closed.
func OpenFifo(ctx context.Context, fn string, flag int, perm os.FileMode) (io.ReadWriteCloser, error)


// Read from a fifo to a byte array.
func (f *fifo) Read(b []byte) (int, error)


// Write from byte array to a fifo.
func (f *fifo) Write(b []byte) (int, error)


// Close the fifo. Next reads/writes will error. This method can also be used
// before open(2) has returned and fifo was never opened.
func (f *fifo) Close() error 

Project details

The fifo is a containerd sub-project, licensed under the Apache 2.0 license. As a containerd sub-project, you will find the:

information in our containerd/project repository.

fifo's People

Contributors

akihirosuda avatar amitkris avatar austinvazquez avatar bentheelder avatar corhere avatar cpuguy83 avatar crosbymichael avatar darfux avatar dmcgowan avatar dqminh avatar ehazlett avatar estesp avatar fangn2 avatar fuweid avatar justincormack avatar mikebrow avatar mlaventure avatar mxpv avatar ningmingxiao avatar samuelkarp avatar stevvooe avatar thajeztah avatar tonistiigi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fifo's Issues

Failed to compile under windwos

vendor\github.com\tonistiigi\fifo\fifo.go:42: undefined: unix.Mkfifo
vendor\github.com\tonistiigi\fifo\handle_nolinux.go:18: undefined: syscall.Stat_t
vendor\github.com\tonistiigi\fifo\handle_nolinux.go:19: undefined: syscall.Stat
vendor\github.com\tonistiigi\fifo\handle_nolinux.go:33: undefined: syscall.Stat_t
vendor\github.com\tonistiigi\fifo\handle_nolinux.go:34: undefined: syscall.Stat

[Darwin] Read() does not always return when closing the reader

I'm seeing different behaviours on MacOS and Linux, when closing a reader.

When running make test with #42 applied, the TestFifoCloseWhileReadingAndWriting fails on MacOS but passes on Linux.

On MacOS, I'm seeing that if I open a writer on a FIFO, closing the reader won't unblock a pending Read() and a Write() from the writer will be received by the reader (After we close the reader):

=== RUN   TestFifoCloseWhileReadingAndWriting
    fifo_test.go:437: 
                Error Trace:    fifo_test.go:437
                Error:          An error is expected but got nil.
                Test:           TestFifoCloseWhileReadingAndWriting
    fifo_test.go:441: Read should not succeed

If there are no writers for the FIFO, closing the reader works as expected on both Linux and MacOS, i.e. the pending Read() returns the expected error (ErrReadClosed).

Copyright is missing

Dear containerd authors,

I would like to package this library for Debian, however I couldn't find a copyright anywhere. This should be mentioned in the LICENSE file as well, right now the copyright line there is just a template.

fifo/LICENSE

Line 189 in fbfb6a1

Copyright [yyyy] [name of copyright owner]

Thanks

fails to compile on arm64 (syscall.Dup2 not available)

syscall.Dup2 is not available on arm64, this breaks building containerd on arm64 after containerd/containerd#4657

It looks like golang/sys@9d4e42a has a wrapper in golang.org/x/sys/unix.Dup2

https://golang.org/pkg/syscall/ says:

Deprecated: this package is locked down. Callers should use the corresponding package in the golang.org/x/sys repository instead. That is also where updates required by new systems or versions should be applied. See https://golang.org/s/go1.4-syscall for more information.

So I think we should probably just switch the package out.

[Bug]:A potential goroutine leak

Hello @samuelkarp, When I used fifo, I found a potential bug, I'm not sure, maybe we can discuss to avoid a goleak
blocking position:

fifo/fifo.go

Lines 124 to 133 in 3e17f98

select {
case <-ctx.Done():
select {
case <-f.opened:
default:
f.Close()
}
case <-f.opened:
case <-f.closed:
}

if users use the OpenFilo() with the parameters like this:
f, err := OpenFifo(context.Background(), filepath.Join(tmpdir, "f0"), syscall.O_RDONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0600)
The select statement will block beacuse there is no cancelFunc to awaken the <-ctx.Done().

I wrote a test function to reproduce the bug considering the test that

func TestFifoCancel(t *testing.T) {

func TestFifoNocancel(t *testing.T) {
	defer goleak.VerifyNone(t)
	tmpdir, err := os.MkdirTemp("", "fifos")
	assert.NoError(t, err)
	defer os.RemoveAll(tmpdir)

	leakCheckWg = &sync.WaitGroup{}
	defer func() {
		leakCheckWg = nil
	}()

	//f, 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_CREAT|syscall.O_NONBLOCK, 0600)
	assert.Exactly(t, nil, f)
	assert.NotNil(t, err)
	assert.NoError(t, checkWgDone(leakCheckWg))
}

The test result shows it is a goroutine leak, you can use goleak to reproduce the bug.
1712307934228

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.