由于java.lang.Runtime异常,我无法定期创建GCP任务:托管通道分配站点



i创建任务如https://cloud.google.com/tasks/docs/creating-appengine-tasks

它在99%的情况下起作用,但有时我会得到以下例外:

java.lang.RuntimeException: ManagedChannel allocation site
at io.grpc.internal.ManagedChannelOrphanWrapper$ManagedChannelReference.<init> (ManagedChannelOrphanWrapper.java:103)
at io.grpc.internal.ManagedChannelOrphanWrapper.<init> (ManagedChannelOrphanWrapper.java:53)
at io.grpc.internal.ManagedChannelOrphanWrapper.<init> (ManagedChannelOrphanWrapper.java:44)
at io.grpc.internal.AbstractManagedChannelImplBuilder.build (AbstractManagedChannelImplBuilder.java:411)
at by.company.application.QueueService.createTask (QueueService.java:76)

queueueService中的方法代码:

 private void createTask(String queueName, String payload, long timeShiftMillis) {
String queuePath = QueueName.of(gcpProjectId, gcpLocation, queueName).toString();
try (CloudTasksClient client = CloudTasksClient.create()) {
    Task.Builder taskBuilder = Task
            .newBuilder()
            .setAppEngineHttpRequest(AppEngineHttpRequest.newBuilder()
                    .setBody(ByteString.copyFrom(payload, Charset.defaultCharset()))
                    .setRelativeUri("/" + queueName)
                    .setHttpMethod(HttpMethod.POST)
                    .build());
    taskBuilder.setScheduleTime(Timestamp
            .newBuilder()
            .setSeconds(Instant.now(Clock.systemUTC()).plusMillis(timeShiftMillis).getEpochSecond()));
    Task build = taskBuilder.build();
    if (!gcpTaskEnabled) {
        return;
    }
    client.createTask(queuePath, build);
} catch (Exception e) {
    LOGGER.log(Level.SEVERE, "Can't create task", e);
}
}

这看起来像https://github.com/googleapis/google-cloud-java/issues/3648。尝试升级到最新版本的Google-cloud-tasks(以及其依赖项)以获取修复。

最新更新