fix race condition because this code is badly architected

This commit is contained in:
olebeck 2022-11-01 23:01:55 +01:00
parent 2157f5b67b
commit b7cc0ff857
1 changed files with 78 additions and 90 deletions

View File

@ -156,8 +156,6 @@ func NewProxy(log *logrus.Logger) *ProxyContext {
var Client_addr net.Addr
func (p *ProxyContext) Run(ctx context.Context, server_address string) (err error) {
c := make(chan struct{})
if strings.HasSuffix(server_address, ".pcap") {
return fmt.Errorf("not supported anymore")
}
@ -165,8 +163,6 @@ func (p *ProxyContext) Run(ctx context.Context, server_address string) (err erro
return create_replay_connection(ctx, p.log, server_address, p.ConnectCB, p.PacketCB)
}
go func() {
defer func() { c <- struct{}{} }()
GetTokenSource() // ask for login before listening
var packs []*resource.Pack
if G_preload_packs {
@ -252,13 +248,5 @@ func (p *ProxyContext) Run(ctx context.Context, server_address string) (err erro
}()
wg.Wait()
}()
select {
case <-ctx.Done():
println("Cancelled")
return context.Canceled
case <-c:
return err
}
}