Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
[LIBCLOUD-835] Fix caching of Google auth tokens #844
Fix corruption bug in Google auth token caching
Fixed, needs tests.
Checklist (tick everything that applies)
_write_token_to_file was not zeroing the file before writing
The change looks good to me. /cc @erjohnso
It's also worth noting that there is still a possibility of a race condition (short window) if multiple instances of script which uses the driver run on the same host. Sadly there is not much we can (and probably should) do.
One option would be to use file based locking, but that's not totally trivial doing it cross-platform if we want to avoid additional dependencies and it's something we should probably outsource to the user (there will always be some possible edge cases and race conditions and sadly we can't take care of all of it).
I think this code could also be made more robust; I believe we're just writing the token as an optimization to speed up the next startup, so failure here shouldn't really tank the app.
Could probably defensively catch all exceptions in the _get_token_from_file() method, instead of just IOErrors; that way if multiple writers clobber the file, the driver will fallback to fetching a new auth token from the API.
It should just degrade and re-authenticate each time instead of exploding like it does right now.
If possible - it would also be great if you can add a test case for it :)
And again thanks and a good catch.
I've started looking at tests, but I'm afraid I probably don't have time to
On Mon, Jul 25, 2016 at 11:31 AM, Tom Melendez email@example.com
I also added logging statement on failure, but we don't really have any common logging standards and practices established in Libcloud yet so that's something we need to improve in the future (among other things, we need to make sure that when