pub_api_client icon indicating copy to clipboard operation
pub_api_client copied to clipboard

Hangs before exit

Open mschwartz opened this issue 4 years ago • 7 comments

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 avatar Sep 14 '21 23:09 mschwartz

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

mschwartz avatar Sep 14 '21 23:09 mschwartz

@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();

leoafarias avatar Sep 15 '21 12:09 leoafarias

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 avatar Sep 15 '21 12:09 mschwartz

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 :))

mschwartz avatar Sep 15 '21 14:09 mschwartz

@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?

leoafarias avatar Sep 15 '21 14:09 leoafarias

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

mschwartz avatar Sep 15 '21 17:09 mschwartz

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

leoafarias avatar Jan 11 '22 13:01 leoafarias

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');
}

f3ath avatar Apr 15 '23 17:04 f3ath

I'm having the same issue.

vlidholt avatar Apr 21 '23 13:04 vlidholt