There have been some ongoing discussions about how to use access tokens efficiently with EF Core (see this blog post for an example), and I'm trying to figure out the right way to use access tokens efficiently. Since I'm a beginner I wanted to try to clear up a thing or two :)
- Once a physical connection has been established to SQL Server/SQL Azure, does it stay valid until physically closed, or is some sort of access token refresh/renegotiation have to occur? In other words, is the access token only important for initially creating/opening the connection, and no longer relevant afterwards?
- From a cursory look at the SqlClient source code, it seems that the access token (and also SqlCredential) is part of the pooling key (SqlConnectionPoolKey). If I understand correctly, this means that if the access token expires and needs to be rotated, a new pool is created, and all the physical connections in the old pool would never get used again, is that right? If so, I'd be interested in understanding why - would it not be possible to omit the access token from the pooling key, reusing the same pool as the token changes during the lifetime of an application? Is this a sort of security measure to require code using SqlClient to always know the access token, i.e. not return an already-open, pooled connection to code which doesn't know it?
- My actual concern here is with the performance implications of getting an access token each time an SqlConnection needs to be opened. Since this may be a heavy operation (i.e. with network traffic), this could be significant, especially where the whole point of pooling is to avoid heavy operations on Open.
- Depending on the answers to the above, would it make sense to imagine SqlConnection accepting a callback that returns an access token, which gets called only if a new physical connection needs to be created? For pooling scenarios, this callback would never be invoked, saving the overhead of fetching a token. With the current situation, user code has no way of knowing whether calling Open will create a new physical connection or not (as pooling is an internal concern), and so must always populate the AccessToken property via what is potentially a heavy operation.
Thanks for taking the time to read and answer the above...!
/cc @ajcvickers
There have been some ongoing discussions about how to use access tokens efficiently with EF Core (see this blog post for an example), and I'm trying to figure out the right way to use access tokens efficiently. Since I'm a beginner I wanted to try to clear up a thing or two :)
Thanks for taking the time to read and answer the above...!
/cc @ajcvickers