Skip to content

Conversation

@BoD
Copy link
Collaborator

@BoD BoD commented Nov 13, 2024

Related to #66

SqlNormalizedCacheFactory.close() will call close() on the SqlDriver it creates - if you pass your own driver, it won't close it.

@BoD BoD requested a review from martinbonnin as a code owner November 13, 2024 09:22
expect fun SqlNormalizedCacheFactory(driver: SqlDriver): NormalizedCacheFactory
fun SqlNormalizedCacheFactory(driver: SqlDriver): NormalizedCacheFactory = SqlNormalizedCacheFactory(driver, false)

internal fun SqlNormalizedCacheFactory(driver: SqlDriver, manageDriver: Boolean): NormalizedCacheFactory =
Copy link
Contributor

@martinbonnin martinbonnin Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The manageDriver here seems inconsistent. I would avoid having to manually define ownership. There are 2 cases:

  1. We want the connection to be shared accross multiple clients => expose it as a public property so the user can retrieve and close it manually if they want to. (see OkHttpClient.dispatcher.executorService.shutdown()).
  2. We want ApolloClient to own the connection => close it systematically.

Option 1. is not breaking current behaviour. On the other hand, 2. is probably what most users expect by default. At the end of the day, it all boils down to whether there's a good case for sharing a connection. I would intuitively say "no" but haven't thought that completely through.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like 1! If we expose the driver, there's no need for a close.

About 2, yeah currently it's possible to pass the same factory to multiple clients, which should probably be forbidden?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's possible to pass the same factory to multiple clients, which should probably be forbidden?

If we forbid sharing a connection between multiple clients, we might as well close the connection systematically when the client is closed. At first sight I would say this is what the majority of users expect.

Copy link
Collaborator Author

@BoD BoD Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot that ApolloClient.close has no knowledge of ApolloStore 😅 To make this happen we could add a ApolloStore.manage(Closeable) sorry I meant ApolloClient.manage(Closeable)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either that or ApolloInterceptor.close() (HttpInterceptor has something like this already for batching IIRC)

Copy link
Contributor

@martinbonnin martinbonnin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. Left one comment. Also probably needs to land in the non-incubating version.

@BoD
Copy link
Collaborator Author

BoD commented Jun 4, 2025

Closing for now until we figure out a satisfying mechanism to handle closing

@BoD BoD closed this Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants