Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hangs before exit #12

Closed
mschwartz opened this issue Sep 14, 2021 · 9 comments · Fixed by #13 or #40
Closed

Hangs before exit #12

mschwartz opened this issue Sep 14, 2021 · 9 comments · Fixed by #13 or #40

Comments

@mschwartz
Copy link

I have a bit of code that calls await packageInfo(packageName) in a loop. The info is properly returned for each package queried.

Yet when I end the loop to exit the program, I don't get a prompt or in the android studio debugger the stop button is enabled as if the program were still running.

There's some sort of timeout that once reached, the program does exit.

I have tried using a single Client instance and one per query, with the same results.

If I were to guess, I'd say the HTTP socket is keep-alive and the code won't exit until that socket is closed.

If this is the case, my suggestion would be some sort of destroy(), close(), or cleanup() on the client instance to force close the socket.

I don't see one here:

https://pub.dev/documentation/pub_api_client/latest/pub_api_client/pub_api_client-library.html or

https://pub.dev/documentation/pub_api_client/latest/pub_api_client/PubClient-class.html

It's probably a good idea to implement such a function, even if it simply returns (for now).

@mschwartz
Copy link
Author

BTW, thanks for this package. It's quite useful.

@leoafarias
Copy link
Owner

@mschwartz did you try calling close on the client?

You can do the following way.

  final client = PubClient();
  final packageScore = await client.packageInfo('provider');
  client.client?.close();

@mschwartz
Copy link
Author

I can do that, thanks.

You still might consider adding a close() method on the PubClient that does the client?close(). If we use that new close() method and you later implement code that requires more cleanup, we all get it for free.

Again, thanks for this package!

@mschwartz
Copy link
Author

Thanks for adding the close method.

However, the issue persists even with calling client.client?.close().

If I comment out the line that calls client.anymethod(), the program exits immediately. Otherwise there's a several second pause at the end.

I've tried creating the client and closing it for each method call as well as one global client that I reuse and close before program is finished.

I could call exit(), but you might want to investigate this (or not :))

@leoafarias leoafarias reopened this Sep 15, 2021
@leoafarias
Copy link
Owner

@mschwartz based on my research it seems there are some open issues in regards to the HttpClient, some even point at malformed responses, so I am not 100% sure if this something that needs to be fixed on pub_api_client

Did you fix to close after each method work?

@mschwartz
Copy link
Author

Close after each method did not solve the problem. I tried both ways: create, query, close, and create, query, query….

@leoafarias
Copy link
Owner

Not being able to replicate this. If there is a sample code that I can use to replicate it would be great

@f3ath
Copy link

f3ath commented Apr 15, 2023

The example code can be used to replicate the issue. The following code hangs for me even with the close() call.

import 'package:pub_api_client/pub_api_client.dart';

void main() async {
  final client = PubClient();
  final packageScore = await client.packageScore('fvm');
  client.close();
  print('Package Score: $packageScore');
}

@vlidholt
Copy link

I'm having the same issue.

@leoafarias leoafarias assigned leoafarias and unassigned leoafarias May 15, 2023
leoafarias added a commit that referenced this issue Aug 8, 2023
Fixes issue when closing client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants