Skip to content

Commit

Permalink
Investigate failure on Windows
Browse files Browse the repository at this point in the history
Signed-off-by: Flavia Rainone <frainone@redhat.com>
  • Loading branch information
fl4via committed Apr 23, 2023
1 parent 01bd95e commit c4cd8da
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
module: [core, servlet, websockets-jsr]
os: [windows-latest] #[ubuntu-latest, windows-latest, macos-latest]
module: [core] #servlet, websockets-jsr]
jdk: [11, 17]
openjdk_impl: [ temurin ]
steps:
Expand Down Expand Up @@ -119,7 +119,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
module: [core, servlet, websockets-jsr]
module: [core] #, servlet, websockets-jsr]
proxy: ['-Pproxy', '']
jdk: [11]
steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package io.undertow.server.protocol.http;

import io.undertow.UndertowLogger;
import io.undertow.UndertowMessages;
import io.undertow.connector.ByteBufferPool;
import io.undertow.connector.PooledByteBuffer;
Expand Down Expand Up @@ -133,7 +134,7 @@ private int processWrite(int state, final Object userData, int pos, int length)
try {
assert state != STATE_BODY;
if (state == STATE_BUF_FLUSH) {
buffer = pooledBuffer.getBuffer();
buffer = getOrAllocateBuffer();//pooledBuffer.getBuffer();
do {
long res = 0;
ByteBuffer[] data;
Expand Down Expand Up @@ -162,6 +163,7 @@ private int processWrite(int state, final Object userData, int pos, int length)
} while (buffer.hasRemaining());
return STATE_BODY;
} else if (state != STATE_START) {
buffer = getOrAllocateBuffer();
return processStatefulWrite(state, userData, pos, length);
}
// make sure that headers are written only once. if
Expand Down Expand Up @@ -222,6 +224,7 @@ private int processWrite(int state, final Object userData, int pos, int length)
this.charIndex = 0;
this.state = STATE_HDR_NAME;
buffer.flip();
UndertowLogger.ROOT_LOGGER.info("WRITING " + header);
return processStatefulWrite(STATE_HDR_NAME, userData, pos, length);
}
header.appendTo(buffer);
Expand All @@ -237,6 +240,7 @@ private int processWrite(int state, final Object userData, int pos, int length)
this.charIndex = 0;
this.state = STATE_HDR_VAL;
buffer.flip();
UndertowLogger.ROOT_LOGGER.info("WRITING2 " + header);
return processStatefulWrite(STATE_HDR_VAL, userData, pos, length);
}
writeString(buffer, string);
Expand Down Expand Up @@ -313,6 +317,17 @@ public void freeContinueResponse() {
}
}

private ByteBuffer getOrAllocateBuffer() {
// allocate pooled buffer
if (pooledBuffer == null) {
pooledBuffer = pool.allocate();
}
// set the state after successfully allocating... so in case something goes bad
// we don't have a dangling flag that won't be cleared at the finally block
this.state |= POOLED_BUFFER_IN_USE;
return pooledBuffer.getBuffer();
}

private static void writeString(ByteBuffer buffer, String string) {
int length = string.length();
for (int charIndex = 0; charIndex < length; charIndex++) {
Expand All @@ -332,6 +347,10 @@ private static void writeString(ByteBuffer buffer, String string) {
*/
private int processStatefulWrite(int state, final Object userData, int pos, int len) throws IOException {
ByteBuffer buffer = pooledBuffer.getBuffer();
// set the state after successfully allocating... so in case something goes bad
// we don't have a dangling flag that won't be cleared at the finally block
this.state |= POOLED_BUFFER_IN_USE;

long fiCookie = this.fiCookie;
int valueIdx = this.valueIdx;
int charIndex = this.charIndex;
Expand All @@ -355,6 +374,7 @@ private int processStatefulWrite(int state, final Object userData, int pos, int
switch (state) {
case STATE_HDR_NAME: {
final HttpString headerName = headerValues.getHeaderName();
//UndertowLogger.ROOT_LOGGER.info("PROCESSING " + headerName);
length = headerName.length();
while (charIndex < length) {
if (buffer.hasRemaining()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@

package io.undertow.server.handlers;

import java.io.IOException;

import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.UndertowLogger;
import io.undertow.testutils.AjpIgnore;
import io.undertow.testutils.DefaultServer;
import io.undertow.util.HttpString;
import io.undertow.testutils.TestHttpClient;
import io.undertow.util.HeaderValues;
import io.undertow.util.HttpString;
import io.undertow.util.StatusCodes;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
Expand All @@ -35,6 +33,9 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;
import java.util.Iterator;

/**
* @author Stuart Douglas
*/
Expand All @@ -50,25 +51,36 @@ public class LotsOfHeadersResponseTestCase {
public static void setup() {
final BlockingHandler blockingHandler = new BlockingHandler();
DefaultServer.setRootHandler(blockingHandler);
blockingHandler.setRootHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) {
for (int i = 0; i < COUNT; ++i) {
exchange.getResponseHeaders().put(HttpString.tryFromString(HEADER + i), MESSAGE + i);
}
blockingHandler.setRootHandler(exchange -> {
for (int i = 0; i < COUNT; ++i) {
exchange.getResponseHeaders().put(HttpString.tryFromString(HEADER + i), MESSAGE + i);
}
for (Iterator<HeaderValues> it = exchange.getResponseHeaders().iterator(); it.hasNext(); ) {
HeaderValues headerValues = it.next();
UndertowLogger.ROOT_LOGGER.info("HEADER AT SERVER SIDE: " + headerValues.getHeaderName() + ": " + headerValues.getFirst());
}
});
}

@Test
public void testLotsOfHeadersInResponse() throws IOException {
Assert.assertTrue(System.getProperty("os.name").startsWith("Windows"));
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
for (int i = 0; i < COUNT; ++i) {
Header[] header = result.getHeaders(HEADER + i);
if (header.length == 0) {
for (Header listedHeader: result.getAllHeaders()) {
UndertowLogger.ROOT_LOGGER.info("HEADER: " + listedHeader.getName() + ": " + listedHeader.getValue());
}
if (result.getAllHeaders().length == 0) {
UndertowLogger.ROOT_LOGGER.info("No header found");
}
Assert.fail("Header " + HEADER + i + " not found");
}
Assert.assertEquals(MESSAGE + i, header[0].getValue());
}
} finally {
Expand Down

0 comments on commit c4cd8da

Please sign in to comment.