about summary refs log tree commit diff
path: root/data_structures_and_algorithms/mesh-message.gv
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-02-09T22·09+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-02-10T10·06+0000
commitd35eb5c8f9a9f74229ec536aa68b52ae9e865f4d (patch)
treeec22c1c0c883970e73c1a6ec5d94c247c018a7b1 /data_structures_and_algorithms/mesh-message.gv
parent323aa41e0fe251189b68d6eaa13de2d58900d838 (diff)
Debug os.Signal handling
Problem:

When SIGINT signals we're sent to the token server, it would shut down without
completing the shutdown procedure. The shutdown procedure would persist the
application state (i.e. access and refresh tokens).

This is problematic for the following sequence of events:
t0. Access and refresh tokens retrieved from kv.json and used as app state.
t1. Tokens are refreshed but not persisted. (I'm still unsure how this
    happens). Remember that this means the previous access and refresh tokens
    from t0 are now invalid.
t2. User sends a SIGINT.
t3. Token server shuts down.
t4. Token server is restarted, kv.json is used as the app state even though its
    tokens are now invalid.
t5. Tokens are attempted to refresh, Monzo API rejects the tokens because
    they're invalid.

Now we need to provide the token server with valid access and refresh tokens
otherwise we will repeat the loop described above. This means going through the
client authorization flow again or copying and pasting the tokens logged from
the token server into kv.json. Either scenario is more manual than I'd prefer.

Solution:

Use a buffered channel to receive the os.Signal. I got this idea after reading
these docs: https://golang.org/pkg/os/signal/#Notify and I debugged this issue
shortly thereafter.

I also rearranged the order of operations in main/0 to ensure that
handleInterrupts/0, which registers the event listeners, occurs before
scheduleTokenRefresh/2 is called. This allows the token server to gracefully
shutdown even if it's in the middle of the scheduleTokenRefresh/2 call.
Diffstat (limited to 'data_structures_and_algorithms/mesh-message.gv')
0 files changed, 0 insertions, 0 deletions