Skip to content

Commit

Permalink
Merge pull request #2112 from dmatej/eclipse-2016-http2Trailers-clear
Browse files Browse the repository at this point in the history
Aggregated fixes from Payara
  • Loading branch information
arjantijms authored Nov 21, 2020
2 parents d6f10c1 + 87569a5 commit a2ce777
Show file tree
Hide file tree
Showing 30 changed files with 772 additions and 491 deletions.
22 changes: 14 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
language: java
dist: trusty
jdk:
- oraclejdk8
os: linux
dist: focal
addons:
apt:
packages:
- openjdk-8-jdk
env:
global:
- PATH=/usr/lib/jvm/java-8-openjdk-amd64/bin/:$PATH
- JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
before_install:
- wget https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
- tar xzvf apache-maven-3.6.3-bin.tar.gz
- export PATH=`pwd`/apache-maven-3.6.3/bin:$PATH
- mvn -v
sudo: false
script: mvn --fail-at-end clean verify
install:
- mvn install -DskipTests=true -Pstaging -Dmaven.javadoc.skip=true -B -V
script: mvn --fail-at-end clean verify -Pstaging

3 changes: 1 addition & 2 deletions modules/bundles/http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-npn-api</artifactId>
<version>${grizzly.alpn.version}</version>
<version>${grizzly.npn.api.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http-server-multipart</artifactId>
</dependency>
</dependencies>

<build>
<defaultGoal>install</defaultGoal>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,19 @@ public CloseType getType() {
*
* If the cause wasn't specified by user and it was closed locally then {@link #LOCALLY_CLOSED} will be returned. If the
* cause wasn't specified by user and it was closed remotely then {@link #REMOTELY_CLOSED} will be returned.
*
*
* @return information about an error, that caused the {@link Connection} to be closed
*/
public IOException getCause() {
return cause;
}


/**
* Returns also type and cause.
*/
@Override
public String toString() {
return super.toString() + "[type="+ getType() + ", cause=" + getCause() + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,18 @@ public final class TaskQueue<E extends AsyncQueueRecord> {
*/
private final Queue<E> queue;

private static final AtomicReferenceFieldUpdater<TaskQueue, AsyncQueueRecord> currentElementUpdater = AtomicReferenceFieldUpdater
.newUpdater(TaskQueue.class, AsyncQueueRecord.class, "currentElement");
private static final AtomicReferenceFieldUpdater<TaskQueue, AsyncQueueRecord> currentElementUpdater
= AtomicReferenceFieldUpdater.newUpdater(TaskQueue.class, AsyncQueueRecord.class, "currentElement");
private volatile E currentElement;

private static final AtomicIntegerFieldUpdater<TaskQueue> spaceInBytesUpdater = AtomicIntegerFieldUpdater.newUpdater(TaskQueue.class, "spaceInBytes");
private static final AtomicIntegerFieldUpdater<TaskQueue> spaceInBytesUpdater
= AtomicIntegerFieldUpdater.newUpdater(TaskQueue.class, "spaceInBytes");
private volatile int spaceInBytes;

private final MutableMaxQueueSize maxQueueSizeHolder;

private static final AtomicIntegerFieldUpdater<TaskQueue> writeHandlersCounterUpdater = AtomicIntegerFieldUpdater.newUpdater(TaskQueue.class,
"writeHandlersCounter");
private static final AtomicIntegerFieldUpdater<TaskQueue> writeHandlersCounterUpdater
= AtomicIntegerFieldUpdater.newUpdater(TaskQueue.class, "writeHandlersCounter");
private volatile int writeHandlersCounter;
protected final Queue<WriteHandler> writeHandlersQueue = new ConcurrentLinkedQueue<>();
// ------------------------------------------------------------ Constructors
Expand Down Expand Up @@ -84,14 +85,15 @@ public int size() {
@SuppressWarnings("unchecked")
public E poll() {
E current = (E) currentElementUpdater.getAndSet(this, null);
return current != null ? current : queue.poll();
return current == null ? queue.poll() : current;
}

/**
* Get the current processing task, if the current in not set, take the task from the queue. Note: after this operation
* call, the current element could be removed from the queue using
* {@link #setCurrentElement(org.glassfish.grizzly.asyncqueue.AsyncQueueRecord)} and passing <tt>null</tt> as a
* parameter, this is a little bit more optimal alternative to {@link #poll()}.
* Get the current processing task, if the current in not set, take the task from the queue.
* <p>
* Note: after this operation call, the current element could be removed from the queue using
* {@link #setCurrentElement(org.glassfish.grizzly.asyncqueue.AsyncQueueRecord)}
* and passing <tt>null</tt> as a parameter, this is a little bit more optimal alternative to {@link #poll()}.
*
* @return the current processing task
*/
Expand Down Expand Up @@ -155,7 +157,7 @@ public int spaceInBytes() {

/**
* Get the queue of tasks, which will be processed asynchronously
*
*
* @return the queue of tasks, which will be processed asynchronously
*/
public Queue<E> getQueue() {
Expand Down Expand Up @@ -209,21 +211,21 @@ private void checkWriteHandlerOnClose(final WriteHandler writeHandler) {
writeHandler.onError(new IOException("Connection is closed"));
}
}
// ------------------------------------------------------- Protected Methods

/**
* Notifies processing the queue by write handlers.
*/
public void doNotify() {
if (maxQueueSizeHolder == null || writeHandlersCounter == 0) {
return;
}

final int maxQueueSize = maxQueueSizeHolder.getMaxQueueSize();

while (spaceInBytes() < maxQueueSize) {
WriteHandler writeHandler = pollWriteHandler();
final WriteHandler writeHandler = pollWriteHandler();
if (writeHandler == null) {
return;
}

try {
writeHandler.onWritePossible();
} catch (Throwable e) {
Expand All @@ -234,7 +236,7 @@ public void doNotify() {

/**
* Set current task element.
*
*
* @param task current element.
*/
public void setCurrentElement(final E task) {
Expand All @@ -260,7 +262,7 @@ public boolean compareAndSetCurrentElement(final E expected, final E newValue) {

/**
* Remove the task from queue.
*
*
* @param task the task to remove.
* @return <tt>true</tt> if tasked was removed, or <tt>false</tt> otherwise.
*/
Expand Down Expand Up @@ -336,8 +338,6 @@ private WriteHandler pollWriteHandler() {
return null;
}

// ----------------------------------------------------------- Nested Classes

public interface MutableMaxQueueSize {
int getMaxQueueSize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ public final class DefaultFilterChain extends ListFacadeFilterChain {

private final FiltersStateFactory filtersStateFactory = new FiltersStateFactory();

/**
* Logger
*/
private static final Logger LOGGER = Grizzly.logger(DefaultFilterChain.class);

public DefaultFilterChain() {
Expand Down Expand Up @@ -101,7 +98,7 @@ public ProcessorResult process(final Context context) {

/**
* Execute this FilterChain.
*
*
* @param ctx {@link FilterChainContext} processing context
*/
@Override
Expand Down Expand Up @@ -242,13 +239,15 @@ protected NextAction executeFilter(final FilterExecutor executor, final Filter c
NextAction nextNextAction;
do {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINE, "Execute filter. filter={0} context={1}", new Object[] { currentFilter, ctx });
LOGGER.log(Level.FINE, "before filter execution. filter={0} context={1}",
new Object[]{currentFilter, ctx});
}
// execute the task
nextNextAction = executor.execute(currentFilter, ctx);

if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINE, "after execute filter. filter={0} context={1} nextAction={2}", new Object[] { currentFilter, ctx, nextNextAction });
LOGGER.log(Level.FINE, "after execute filter. filter={0} context={1} nextAction={2}",
new Object[] { currentFilter, ctx, nextNextAction });
}
} while (nextNextAction.type() == RerunFilterAction.TYPE);

Expand Down Expand Up @@ -402,7 +401,7 @@ public void fail(FilterChainContext context, Throwable failure) {

/**
* Notify the filters about error.
*
*
* @param ctx {@link FilterChainContext}
* @return position of the last executed {@link Filter}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*
*
* Contributors:
* Payara Services - Add support for JDK 9 ALPN API
* - Propagate stop action on a closed SSL connection
Expand Down Expand Up @@ -193,7 +193,7 @@ public long getHandshakeTimeout(final TimeUnit timeUnit) {

/**
* Sets the handshake timeout.
*
*
* @param handshakeTimeout timeout value, or <code>-1</code> means for non-blocking handshake mode.
* @param timeUnit {@link TimeUnit}
*/
Expand Down Expand Up @@ -794,9 +794,7 @@ private static Certificate[] getPeerCertificates(final SSLConnectionContext sslC
try {
return sslCtx.getSslEngine().getSession().getPeerCertificates();
} catch (Throwable t) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Error getting client certs", t);
}
LOGGER.log(Level.FINE, "Error getting client certs", t);
return null;
}
}
Expand Down Expand Up @@ -892,14 +890,6 @@ public void onComplete(final Context context, Object data) throws IOException {

} // END InternalProcessingHandler

public interface HandshakeListener {
void onStart(Connection<?> connection);

void onComplete(Connection<?> connection);

void onFailure(Connection<?> connection, Throwable t);
}

protected static class SSLTransportFilterWrapper extends TransportFilter {
protected final TransportFilter wrappedFilter;
protected final SSLBaseFilter sslBaseFilter;
Expand Down Expand Up @@ -1009,4 +999,15 @@ public Buffer clone(final Connection connection, final Buffer originalMessage) {
return originalMessage;
}
}


// don't move to own file, Tyrus has a dependency on this interface
public interface HandshakeListener {
default void onInit(Connection<?> connection, SSLEngine sslEngine) {
// nothing
}
void onStart(Connection<?> connection);
void onComplete(Connection<?> connection);
void onFailure(Connection<?> connection, Throwable t);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public final class SSLConnectionContext {
}

final ByteBufferArray outputByteBufferArray = ByteBufferArray.create();

final ByteBufferArray inputByteBufferArray = ByteBufferArray.create();

private Buffer lastOutputBuffer;
Expand Down Expand Up @@ -225,11 +224,9 @@ Buffer wrapAll(final Buffer input, final Allocator allocator) throws SSLExceptio
if (input.hasRemaining()) {
do {
result = wrap(input, inputArray, inputArraySize, null, allocator);

if (result.isError()) {
throw result.getError();
}

final Buffer newOutput = result.getOutput();
newOutput.trim();

Expand Down Expand Up @@ -272,13 +269,11 @@ private SslResult wrap(final Buffer input, final ByteBuffer[] inputArray, final
}

final Status status = sslEngineResult.getStatus();

if (status == Status.CLOSED) {
return new SslResult(output, new SSLException("SSLEngine is CLOSED"));
}

final boolean isOverflow = status == Status.BUFFER_OVERFLOW;

if (allocator != null && isOverflow) {
updateBufferSizes();
output = ensureBufferSize(output, netBufferSize, allocator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public static HttpContent create(final HttpHeader httpHeader, final boolean isLa

public static HttpContent create(final HttpHeader httpHeader, final boolean isLast, Buffer content) {
content = content != null ? content : Buffers.EMPTY_BUFFER;

final HttpContent httpContent = ThreadCache.takeFromCache(CACHE_IDX);
if (httpContent != null) {
httpContent.httpHeader = httpHeader;
Expand Down Expand Up @@ -137,10 +136,8 @@ public final HttpHeader getHttpHeader() {
}

/**
* Return <tt>true</tt>, if the current content chunk is last, or <tt>false</tt>, if there are content chunks to follow.
*
* @return <tt>true</tt>, if the current content chunk is last, or <tt>false</tt>, if there are content chunks to
* follow.
* @return <tt>true</tt>, if the current content chunk is last,
* or <tt>false</tt>, if there are content chunks to follow.
*/
public boolean isLast() {
return isLast;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class HttpTrailer extends HttpContent implements MimeHeadersPacket {
* @return <tt>true</tt> if passed {@link HttpContent} is a <tt>HttpTrailder</tt>.
*/
public static boolean isTrailer(HttpContent httpContent) {
return HttpTrailer.class.isAssignableFrom(httpContent.getClass());
return httpContent != null && HttpTrailer.class.isAssignableFrom(httpContent.getClass());
}

public static HttpTrailer create() {
Expand Down
Loading

0 comments on commit a2ce777

Please sign in to comment.