Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package com.here.xyz.jobs.service;

import static com.here.xyz.jobs.RuntimeInfo.State.CANCELLING;
import static com.here.xyz.jobs.RuntimeInfo.State.FAILED;
import static com.here.xyz.jobs.RuntimeInfo.State.NOT_READY;
import static com.here.xyz.jobs.RuntimeInfo.State.RUNNING;
Expand Down Expand Up @@ -47,12 +48,15 @@
import com.here.xyz.util.service.BaseHttpServerVerticle.ValidationException;
import com.here.xyz.util.service.HttpException;
import com.here.xyz.util.service.errors.DetailedHttpException;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.Future;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.openapi.router.RouterBuilder;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.commons.lang3.NotImplementedException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -87,10 +91,27 @@ protected void postJob(final RoutingContext context) throws HttpException {

protected Future<Job> createNewJob(RoutingContext context, Job job) {
logger.info(getMarker(context), "Received job creation request: {}", job.serialize(true));
AtomicBoolean clientGone = new AtomicBoolean(false);

context.request().connection().closeHandler(v -> {
clientGone.set(true);
});

return job.create().submit()
.compose(v -> abortIfClientGone(clientGone))
.compose(v -> applyInputReferences(job))
.compose(v -> abortIfClientGone(clientGone))
.map(res -> job)
.recover(t -> {
if(t instanceof HttpException e && e.status == HttpResponseStatus.GONE) {
Comment thread
roegi marked this conversation as resolved.
logger.warn(getMarker(context), e.getMessage());
job.getStatus()
Copy link
Copy Markdown
Contributor

@mujammil10 mujammil10 Mar 2, 2026

Choose a reason for hiding this comment

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

Shouldn't we call job.cancel() here or inside the #abortIfClientGone ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In this case we cant provide a proper errorMessage.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We will not be able to provide the error message anyway, coz the client closed the connection already.
Also, if we do not cancel the job, it will still be executing in the step function.

.withState(CANCELLING)
.withErrorMessage("Client disconnected.")
Comment thread
roegi marked this conversation as resolved.
Outdated
.withErrorCause(t.getMessage());
job.store();
Comment thread
roegi marked this conversation as resolved.
Outdated
return Future.failedFuture(e);
}
if (t instanceof CompilationError)
return Future.failedFuture(new DetailedHttpException("E319002", t));
if (t instanceof ValidationException)
Expand All @@ -104,6 +125,13 @@ protected Future<Job> createNewJob(RoutingContext context, Job job) {
.onFailure(err -> sendErrorResponse(context, err));
}

private <T> Future<T> abortIfClientGone(AtomicBoolean clientGone) {
if (clientGone.get()) {
return Future.failedFuture(new HttpException(HttpResponseStatus.GONE,"Client disconnected during job creation. Aborting job."));
}
return Future.succeededFuture();
}

protected Future<Void> applyInputReferences(Job job) {
if (job.getInputs() == null)
return Future.succeededFuture();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package com.here.xyz.util.db;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
Expand All @@ -28,9 +30,11 @@
import org.xbill.DNS.Lookup;
import org.xbill.DNS.Record;
import org.xbill.DNS.Name;
import org.xbill.DNS.SimpleResolver;

public class DBClusterResolver {
private static final Pattern RDS_CLUSTER_HOSTNAME_PATTERN = Pattern.compile("(.+).cluster-.*.rds.amazonaws.com.*");
private static final int DNS_LOOKUP_TIMEOUT_SECONDS = 2;

public static String getClusterIdFromHostname(String hostname) {
if(hostname == null) return null;
Expand All @@ -44,7 +48,10 @@ private static String extractClusterId(String url) {

private static String resolveAndExtractClusterId(String hostname) {
try {
SimpleResolver resolver = new SimpleResolver();
resolver.setTimeout(Duration.of(DNS_LOOKUP_TIMEOUT_SECONDS, ChronoUnit.SECONDS));
Lookup lookup = new Lookup(hostname);
lookup.setResolver(resolver);

List<String> records = Arrays.stream(lookup.run()).map(Record::toString).collect(Collectors.toList());
records.addAll(Arrays.stream(lookup.getAliases()).map(Name::toString).collect(Collectors.toList()));
Expand Down