Code Monkey home page Code Monkey logo

shared-conn's Introduction

Shared Conn

Passing a net.Conn between processes.

Intro

Toy program meant to address this go forum issue.

This program creates a listener by binding to the supplied address, accesses the underlying FD, and passes it to a child process.

The child process recreates the listener using the shared FD, then attempts to rebind the same address as the parent.

It exposes two issues via command line flags.

Setup

go get github.com/jdhenke/shared-conn

Usage

$ shared-conn -h
Usage of shared-conn:
  -addr string
    	address on which to listen (default ":1234")
  -ignoreFiles
    	ignore closing FDs
  -triggerRace
    	trigger race condition

Example

Running with default settings should pass, although a race exists.

$ shared-conn
parent | 17:36:02.190679 Using address=`:1234`
parent | 17:36:02.193514 Closed listener.
parent | 17:36:02.193528 Closed file.
child  | 17:36:02.196729 Using address=`:1234`
child  | 17:36:02.196920 Closed listener.
child  | 17:36:02.196929 Closed file.
child  | 17:36:02.196931 Rebinding...
child  | 17:36:02.196983 PASS
parent | 17:36:02.197860 PASS

Running with trigger race should fail, although a race exists.

$ shared-conn -triggerRace
parent | 17:36:08.220841 Using address=`:1234`
child  | 17:36:08.226717 Using address=`:1234`
child  | 17:36:08.226917 Closed listener.
child  | 17:36:08.226921 Closed file.
child  | 17:36:08.226922 Rebinding...
child  | 17:36:08.226972 Child could not recreate listener: listen tcp :1234: bind: address already in use
parent | 17:36:10.226090 Closed listener.
parent | 17:36:10.226135 Closed file.
parent | 17:36:10.226188 Child process error: exit status 1

Leaving the files open then attempting to rebind should always fail.

$ shared-conn -ignoreFiles
parent | 17:36:14.632811 Using address=`:1234`
parent | 17:36:14.635907 Closed listener.
child  | 17:36:14.638920 Using address=`:1234`
child  | 17:36:14.639092 Closed listener.
child  | 17:36:14.639095 Rebinding...
child  | 17:36:14.639142 Child could not recreate listener: listen tcp :1234: bind: address already in use
parent | 17:36:14.639982 Child process error: exit status 1

shared-conn's People

Contributors

mholt avatar

Watchers

 avatar

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.