Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Pass context to proxy.Run() or proxy.Wait() function #34

Open
@snehainguva

Description

Using the proxy code and noticed that the current implementation makes it slightly hard to propagate context cancellation through the proxy.Run() function. I've temporarily addressed this issue by using error groups and calling proxy.Close():

	eg.Go(func() error {
		<-ctx.Done()
		proxy.Close()
		return ctx.Err()
	})
	eg.Go(func() error {
		if err := s.proxy.Run(); err != nil {
 // If context has been cancelled, terminate goroutine and return no error.
			if ctx.Err() != nil {
				return nil
			}
			return err
		}
 return nil
	})

However, this created a raciness issue which eventually led me to creating a SafeProxy type that wrapped the proxy with a mutex:

i.e.

type SafeProxy struct {
	mu sync.Mutex
	proxy *tcpproxy.Proxy
}

However, if the original Run or Wait functions were to actually take a context (i.e. proxy.Run(ctx) or proxy.Wait(ctx), that would make it easy to gracefully terminate the proxy.

I'm also happy to work on a PR to implement this if there is any interest!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /