Skip to content

Netty max open connections test #31265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: netty-transport-http
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion dev/io.openliberty.netty.internal.impl/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ Import-Package: \
# reuse the existing translated messages from the TCP Channel
Private-Package: \
com.ibm.ws.tcpchannel.internal.resources, \
com.ibm.ws.udpchannel.internal.resources
com.ibm.ws.udpchannel.internal.resources, \
com.ibm.ws.channelfw.internal.resources

-dsannotations: \
io.openliberty.netty.internal.impl.NettyFrameworkImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface NettyConstants {

/** RAS trace bundle for NLS */
String BASE_BUNDLE = "io.openliberty.netty.internal.impl.resources.NettyFrameworkMessages";
String CF_BUNDLE = "com.ibm.ws.channelfw.internal.resources.ChannelfwMessages";
/** RAS trace group name */
String NETTY_TRACE_NAME = "Netty";
/** default trace string */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GlobalEventExecutor;
import io.openliberty.netty.internal.BootstrapConfiguration;
import io.openliberty.netty.internal.BootstrapExtended;
import io.openliberty.netty.internal.NettyFramework;
import io.openliberty.netty.internal.ServerBootstrapExtended;
import io.openliberty.netty.internal.exception.NettyException;
import io.openliberty.netty.internal.tcp.TCPConfigConstants;
import io.openliberty.netty.internal.tcp.TCPConfigurationImpl;
import io.openliberty.netty.internal.tcp.TCPUtils;
import io.openliberty.netty.internal.udp.UDPUtils;

import com.ibm.websphere.channelfw.EndPointMgr;

/**
Expand All @@ -71,7 +74,7 @@
public class NettyFrameworkImpl implements ServerQuiesceListener, NettyFramework {

private static final TraceComponent tc = Tr.register(NettyFrameworkImpl.class, NettyConstants.NETTY_TRACE_NAME,
NettyConstants.BASE_BUNDLE);
NettyConstants.CF_BUNDLE);

/** Reference to the executor service -- required */
private ExecutorService executorService = null;
Expand Down Expand Up @@ -458,7 +461,13 @@ protected synchronized void unsetServerStarted(ServiceReference<ServerStarted> r

@Override
public ServerBootstrapExtended createTCPBootstrap(Map<String, Object> tcpOptions) throws NettyException {
return TCPUtils.createTCPBootstrap(this, tcpOptions);
try{
return TCPUtils.createTCPBootstrap(this, tcpOptions);
} catch (NettyException e){
Tr.error(tc, "chain.initialization.error", new Object[] { tcpOptions.get("ExternalName"), e.toString() });
throw e;
}

}

@Override
Expand All @@ -479,7 +488,21 @@ public BootstrapExtended createUDPBootstrapOutbound(Map<String, Object> options)
@Override
public Channel start(ServerBootstrapExtended bootstrap, String inetHost, int inetPort,
ChannelFutureListener bindListener) throws NettyException {
return TCPUtils.start(this, bootstrap, inetHost, inetPort, bindListener);

BootstrapConfiguration config = bootstrap.getConfiguration();
// TODO: clean this up, theoretically we should always have an externalName.
// Bootstrap class doesnt have a non-null default either. For now setting it to NOT_DEFINED.
String externalName = "NOT_DEFINED";
if(config!= null && config instanceof TCPConfigurationImpl){
externalName = ((TCPConfigurationImpl)config).getExternalName();
}

try{
return TCPUtils.start(this, bootstrap, inetHost, inetPort, bindListener);
}catch(NettyException e){
Tr.error(tc, "chain.initialization.error", new Object[] { externalName, e.toString() });
throw e;
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2022 IBM Corporation and others.
* Copyright (c) 2021, 2025 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -14,6 +14,7 @@
import com.ibm.websphere.ras.Tr;
import com.ibm.websphere.ras.TraceComponent;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
Expand Down Expand Up @@ -47,6 +48,14 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception {
long currentTime = System.currentTimeMillis();
if (currentTime > (lastConnExceededTime + 600000L)) {
String channelName = ctx.channel().attr(ConfigConstants.NAME_KEY).get();

// If the channelName is null check the parent for a name.
if (channelName == null) {
Channel parentChannel = ctx.channel().parent();
if (parentChannel != null) {
channelName = parentChannel.attr(ConfigConstants.NAME_KEY).get();
}
}
Tr.warning(tc, TCPMessageConstants.MAX_CONNS_EXCEEDED, channelName, maxConnections);
lastConnExceededTime = currentTime;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2023 IBM Corporation and others.
* Copyright (c) 2021, 2025 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -35,13 +35,13 @@ public class TCPChannelInitializerImpl extends ChannelInitializerWrapper {
TCPMessageConstants.TCP_BUNDLE, TCPChannelInitializerImpl.class.getName());

TCPConfigurationImpl config;

NettyFrameworkImpl bundle;
MaxOpenConnectionsHandler maxHandler;

public TCPChannelInitializerImpl(BootstrapConfiguration config, NettyFrameworkImpl bundle) {
this.bundle = bundle;
this.config = (TCPConfigurationImpl) config;
maxHandler = new MaxOpenConnectionsHandler(this.config.getMaxOpenConnections());
}

@Override
Expand All @@ -60,7 +60,6 @@ protected void initChannel(Channel channel) throws Exception {
if (config.getInactivityTimeout() > 0) {
channel.pipeline().addLast(NettyConstants.INACTIVITY_TIMEOUT_HANDLER_NAME, new InactivityTimeoutHandler(0, 0, config.getInactivityTimeout(), TimeUnit.MILLISECONDS));
}
MaxOpenConnectionsHandler maxHandler = new MaxOpenConnectionsHandler(config.getMaxOpenConnections());
if (config.getAccessLists() != null) {
AccessListHandler includeHandler = new AccessListHandler(config.getAccessLists());
channel.pipeline().addLast(NettyConstants.ACCESSLIST_HANDLER_NAME, includeHandler);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2022 IBM Corporation and others.
* Copyright (c) 2021, 2025 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -118,6 +118,10 @@ public TCPConfigurationImpl(Map<String, Object> options, boolean inbound) throws
this.channelProperties = options;

if (this.channelProperties != null) {
// Set the name of the channel before setting the values of the other properties. This ensures it is available
// if a validation error occurs.
this.externalName = (String) this.channelProperties.get(ConfigConstants.EXTERNAL_NAME);

// read in values now, to save time reading them in each time
// they are requested
setValues();
Expand Down Expand Up @@ -160,7 +164,10 @@ public AddressAndHostNameAccessLists getAccessLists() {

//@formatter:off
private boolean skipKey(String key) {
return key.equals("id") ||
// We set externalName in the constructor. If we don't skip it while processing the rest of the properties the below error occurs:
// CWWKO0212W: TCP Channel defaultHttpEndpoint has been constructed with an incorrect configuration property. Property Name: ExternalName Value: defaultHttpEndpoint
return key.equals(ConfigConstants.EXTERNAL_NAME) || // Skip ExternalName since it was set in the constructor.
key.equals("id") ||
key.equals("type") ||
key.startsWith("service.") ||
key.startsWith("component.") ||
Expand Down Expand Up @@ -199,13 +206,7 @@ private void setValues() throws NettyException {
value = entry.getValue();

if (skipKey(key)) {
// skip osgi standard properties
continue;
}

// add the name for the channel
if (key.equalsIgnoreCase(ConfigConstants.EXTERNAL_NAME)) {
this.externalName = (String) value;
// skip osgi standard properties and ExternalName
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@RunWith(Suite.class)
@SuiteClasses({
AccessListsTests.class,
MaxOpenConnectionsTest.class
MaxOpenConnectionsTests.class
})
public class FATSuite {

Expand Down

This file was deleted.

Loading