Fix multi host data source type reloading by NinoFloris · Pull Request #6238 · npgsql/npgsql

What a nice bug.

We should probably consider whether we want a direct call to connection.ReloadTypes() (as opposed to multihostdatasource.ReloadTypes()) to only reload the concrete data source.

While I highly doubt anyone will ever call connection.ReloadTypes() on read-only connection (given that what most likely happens is that you first create/update a type and when want to reload), I would probably argue that it's better for multihost scenario to wire that call to multihostdatasource.ReloadTypes() just because it's much more predictable in it's behavior (after that call you're completely sure that each new connection you get will have the new type, no matter the host it decides) plus, ideally ReloadTypes shouldn't take too long.

Now, here's another tricky question. Let's say we have two hosts and the first host is down, so we only connect to second (and it's primary). Currently, multihostdatasource.ReloadTypes() will immediately fail and throw an exception even though it's not a critical error, and the worst thing, you're unable to actually reload types for the second host. Maybe what instead we should do is:

  1. Go over each host and aggregate exceptions to throw them together afterwards
  2. In case we do fail to reload types, maybe NpgsqlDataSource.Bootstrap should set IsBootstrapped to false whenever it's called with forceReload = true to make sure the next successful Open reloads types