Skip to content

Commit

Permalink
#192 Fixed hanging response when adding invalid queue item
Browse files Browse the repository at this point in the history
  • Loading branch information
mcweba committed Jul 3, 2024
1 parent c87ac31 commit aa6d854
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import org.swisspush.redisques.QueueStatsService;
import org.swisspush.redisques.QueueStatsService.GetQueueStatsMentor;
import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.util.DequeueStatistic;
import org.swisspush.redisques.util.DequeueStatisticCollector;
import org.swisspush.redisques.util.QueueStatisticsCollector;
import org.swisspush.redisques.util.RedisquesAPI;
import org.swisspush.redisques.util.RedisquesConfiguration;
import org.swisspush.redisques.util.Result;
import org.swisspush.redisques.util.StatusCode;

import javax.annotation.Nullable;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
Expand Down Expand Up @@ -878,13 +878,17 @@ private void bulkDeleteQueues(RoutingContext ctx) {
}
}

private void respondWith(StatusCode statusCode, String responseMessage, HttpServerRequest request) {
private void respondWith(StatusCode statusCode, @Nullable String responseMessage, HttpServerRequest request) {
final HttpServerResponse response = request.response();
log.info("Responding with status code {} and message '{}' to request '{}'", statusCode, responseMessage, request.uri());
response.setStatusCode(statusCode.getStatusCode());
response.setStatusMessage(statusCode.getStatusMessage());
response.putHeader(CONTENT_TYPE, TEXT_PLAIN);
response.end(responseMessage);
if(responseMessage != null) {
response.end(responseMessage);
} else {
response.end();
}
}

private void respondWith(StatusCode statusCode, HttpServerRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,11 @@ public void addQueueItemInvalidBody(TestContext context) {
assertKeyCount(context, getQueuesRedisKeyPrefix(), 0);
context.assertEquals(0L, jedis.llen(getQueuesRedisKeyPrefix() + queueName));

// this body creates a NullpointerException because there is no header property
given().body(configurationValid).when().post("/queuing/queues/" + queueName + "/").then().assertThat().statusCode(400);
assertKeyCount(context, getQueuesRedisKeyPrefix(), 0);
context.assertEquals(0L, jedis.llen(getQueuesRedisKeyPrefix() + queueName));

async.complete();
}

Expand Down

0 comments on commit aa6d854

Please sign in to comment.