Skip to content

Commit

Permalink
fix api fd leak
Browse files Browse the repository at this point in the history
  • Loading branch information
p4gefau1t committed Jul 14, 2020
1 parent 3b63cc2 commit 9dc8a7c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api/service/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func RunClientAPI(ctx context.Context, auth statistic.Authenticator) error {
if err != nil {
return err
}
defer server.Stop()
service := &ClientAPI{
ctx: ctx,
auth: auth,
Expand All @@ -77,6 +78,7 @@ func RunClientAPI(ctx context.Context, auth statistic.Authenticator) error {
if err != nil {
return common.NewError("client api failed to listen").Base(err)
}
defer listener.Close()
log.Info("client-side api service is listening on", listener.Addr().String())
errChan := make(chan error, 1)
go func() {
Expand All @@ -86,7 +88,6 @@ func RunClientAPI(ctx context.Context, auth statistic.Authenticator) error {
case err := <-errChan:
return err
case <-ctx.Done():
server.Stop()
return nil
}
}
Expand Down
3 changes: 2 additions & 1 deletion api/service/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ func RunServerAPI(ctx context.Context, auth statistic.Authenticator) error {
if err != nil {
return err
}
defer server.Stop()
RegisterTrojanServerServiceServer(server, service)
addr, err := net.ResolveIPAddr("ip", cfg.API.APIHost)
if err != nil {
Expand All @@ -239,6 +240,7 @@ func RunServerAPI(ctx context.Context, auth statistic.Authenticator) error {
if err != nil {
return common.NewError("server api failed to listen").Base(err)
}
defer listener.Close()
log.Info("server-side api service is listening on", listener.Addr().String())
errChan := make(chan error, 1)
go func() {
Expand All @@ -248,7 +250,6 @@ func RunServerAPI(ctx context.Context, auth statistic.Authenticator) error {
case err := <-errChan:
return err
case <-ctx.Done():
server.Stop()
return nil
}
}
Expand Down

0 comments on commit 9dc8a7c

Please sign in to comment.