Server Close is never called

Hi
I've been using traefik for a while and I noticed something that seemed strange, hoping it's not my misunderstanding!

in pkg/server/server.go in function Start(), we have a go routine that waits for a stop signal to try and shut down traefik gracefully. In it, there are 2 methods that got my attention: s.Close() and s.Stop().

In Stop(), entrypoints are being shut down with a (10s) timeout.
In Close(), channels are being closed and close methods of every instances are being called. This is also with a (10s) timeout.

What I noticed, is this flow:
The program stops when stopChan is set to true. (server's Wait() method)
stopChan is set to true in Stop() method.
Stop() method is called before Close() method! (because Close() is called with defer)

This means that Close() method doesn't have the chance to run because the program is already finished!

I tried to run in debug mode and when I stopped the program, the Stop() method is called, but Close() method is NOT!

Anyone could confirm which is true, my misunderstanding or traefik bug?

Thanks

Hello,

The Close() is called.

I added a log to show you the call:

INFO[2019-11-25T00:37:11+01:00] Server stopped                               
INFO[2019-11-25T00:37:11+01:00] Call method Close
INFO[2019-11-25T00:37:11+01:00] Shutting down  

I again tried to trace it and saw that the Close is actually called, but not completely!!

I traced program to the line s.routinesPool.Close() and till this line it is executed, but whatever comes after this line is not!

So maybe this line is problematic?

So I merged with master, on v2.1.0-rc3, and I saw that not only the problem exists, but there rose another problem!
When you start program, the dynamic configs are loaded "2 times"! For example, this log:

DEBU[2019-12-07T22:59:53+03:30] Creating middleware                           entryPointName=web middlewareName=traefik-internal-recovery middlewareType=Recovery

appears once and then appears again instantly! I traced and saw that for every middleware this happens!

Any further response would be appreciated.

P.S, I suspect that this merge request caused this problem :-?

I don't reproduce the twice load of dynamic config.

About the server Close: https://github.com/containous/traefik/pull/5960

1 Like