googleads / google-ads-java

Google Ads API Client Library for Java
Apache License 2.0
171 stars 176 forks source link

API got stuck when create a video asset #807

Closed Wale-Shi closed 1 week ago

Wale-Shi commented 3 weeks ago

Java Code that inside a for loop to upload one youtube asset to multiple accounts (example account : 7088033821)

here is the code :

String s = upload2Youtube(url, fileName);
PitcherLogger.info("upload to Youtube Success , ID:" + s);
// Create the videoAsset.
YoutubeVideoAsset videoAsset = YoutubeVideoAsset.newBuilder().setYoutubeVideoId(s).build();

// Creates an asset.
Asset asset =
Asset.newBuilder()
// Provide a unique friendly name to identify your asset.
// When there is an existing image asset with the same content but a different name, the
// new name will be dropped silently.
.setName(fileName)
.setType(AssetTypeEnum.AssetType.YOUTUBE_VIDEO)
.setYoutubeVideoAsset(videoAsset)
.build();

// Creates the operation.
AssetOperation operation = AssetOperation.newBuilder().setCreate(asset).build();

int uploadTimes = 1;
// Creates the service client.
try (AssetServiceClient assetServiceClient =
googleAdsClient.getLatestVersion().createAssetServiceClient()) {
do {
try {
// Issues a mutate request to add the asset.
MutateAssetsResponse response =
assetServiceClient.mutateAssets(account, ImmutableList.of(operation));
PitcherLogger.info("upload to Google Ads Success , ID:" + response.getResults(0).getResourceName());
// Prints the result.
return response.getResults(0).getResourceName();
} catch (Throwable e) {
PitcherLogger.error("upload to Google Ads Assets Exception Retry " + uploadTimes , e);
// Waiting for a few seconds
Thread.sleep(uploadTimes*5000L);
uploadTimes++;

}
} while (uploadTimes <= 3);
PitcherLogger.error("create Google Video Asset Fail");
throw new RPCException("create Google Video Asset Fail");
}
} catch (Exception e) {
PitcherLogger.error("upload to Google Exception Retry " , e);
throw new RPCException(e);
}

Issue Observed: After 2-3 success in the for loop, the program will get stuck on line MutateAssetsResponse response = assetServiceClient.mutateAssets(account, ImmutableList.of(operation)); without any return or error.

when we dump the jstack info, we found below thread is WAITING

"Schedulerx-Container-Thread-2560181_11078847447_1" Id=1463 WAITING on com.google.api.core.AbstractApiFuture$InternalSettableFuture@6fc03e3a at sun.misc.Unsafe.park0(Native Method)

jradcliff commented 3 weeks ago

Hi,

That thread dump suggests that the library is simply waiting for a response from the server, so this may be an issue with the API and not the library. To help us assess what's happening:

  1. Before the upload gets stuck, do your logs show anything of interest such as failures logged via PitcherLogger.error?
  2. Does the request get stuck only when it is a retry request?
  3. Do you have the request IDs returned from the successful responses before the failure?

Thanks, Josh, Google Ads API Team

hongxin1988 commented 3 weeks ago

Hi,

That thread dump suggests that the library is simply waiting for a response from the server, so this may be an issue with the API and not the library. To help us assess what's happening:

  1. Before the upload gets stuck, do your logs show anything of interest such as failures logged via PitcherLogger.error?
  2. Does the request get stuck only when it is a retry request?
  3. Do you have the request IDs returned from the successful responses before the failure?

Thanks, Josh, Google Ads API Team

1、There aren't any error logs before getting stuck. 2、No. 3、Yes, just as the follow logs show. After the third line, it got stuck when calling mutateAssets with the youtube video id "J6RkgYAw-9A" in the parameter.

[2024-08-20 05:27:44.186] INFO ...- upload to Youtube Success , ID:0QOFJDDYDDk【succeed in uploading】 [2024-08-20 05:27:54.628] INFO ... - upload to Google Ads Success , ID:customers/2839667411/assets/163539540995 【succeed in mutateAssets with ID:0QOFJDDYDDk】 [2024-08-20 05:27:58.496] INFO ... upload to Youtube Success , ID:J6RkgYAw-9A 【After this it got stuck when calling mutateAssets with this ID:J6RkgYAw-9A 】

Thanks.

jradcliff commented 3 weeks ago

Are you able to add more verbose logging for io.grpc loggers so we can see what's happening when the requests stall?

Thanks

jradcliff commented 1 week ago

I haven't heard back on my last question for 2 weeks so I'll close this issue, but feel free to reopen with a reply to that question if you're still encountering problems.

Thanks