This is an automated email from the ASF dual-hosted git repository.
Havret pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-nms-amqp.git
The following commit(s) were added to refs/heads/main by this push:
new 35a804e fixed casting of IdleTimeOut
35a804e is described below
commit 35a804ebf12247c58284966e4d0a4f4c124b41ff
Author: Federico Barresi <[email protected]>
AuthorDate: Mon Apr 20 16:11:57 2026 +0200
fixed casting of IdleTimeOut
Since AmqpNetLite v2.4.8 the IdleTimeOut supports negative values.
The new default value is -1.
If the timeout of -1 get casted to uint it becames uint.MaxValue.
This lead to wrong working heartbeat and high CPU usage.
---
src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs | 5 +-
.../Provider/Amqp/AmqpConnectionTest.cs | 76 ++++++++++++++++++++++
2 files changed, 80 insertions(+), 1 deletion(-)
diff --git a/src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs
b/src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs
index 85c2edb..fa05fbb 100644
--- a/src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs
+++ b/src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs
@@ -115,7 +115,10 @@ namespace Apache.NMS.AMQP.Provider.Amqp
open.ChannelMax = Info.ChannelMax;
open.MaxFrameSize = (uint) Info.MaxFrameSize;
open.HostName = String.IsNullOrWhiteSpace(this.Provider.VHost) ?
remoteUri.Host : this.Provider.VHost;
- open.IdleTimeOut = (uint) Info.IdleTimeOut;
+ if (Info.IdleTimeOut > 0)
+ {
+ open.IdleTimeOut = (uint)Info.IdleTimeOut;
+ }
open.DesiredCapabilities = new[]
{
SymbolUtil.OPEN_CAPABILITY_SOLE_CONNECTION_FOR_CONTAINER,
diff --git a/test/Apache-NMS-AMQP-Test/Provider/Amqp/AmqpConnectionTest.cs
b/test/Apache-NMS-AMQP-Test/Provider/Amqp/AmqpConnectionTest.cs
new file mode 100644
index 0000000..be62332
--- /dev/null
+++ b/test/Apache-NMS-AMQP-Test/Provider/Amqp/AmqpConnectionTest.cs
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using Amqp.Framing;
+using Apache.NMS.AMQP.Meta;
+using Apache.NMS.AMQP.Provider;
+using Apache.NMS.AMQP.Provider.Amqp;
+using NUnit.Framework;
+
+namespace NMS.AMQP.Test.Provider.Amqp
+{
+ [TestFixture]
+ public class AmqpConnectionTest
+ {
+ private AmqpProvider provider;
+ private AmqpConnection connection;
+ private AmqpHandler handler;
+
+ [SetUp]
+ public void Setup()
+ {
+ provider = ProviderFactory.Create(GetDefaultUri()) as AmqpProvider;
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ if (provider != null)
+ {
+ provider.Close();
+ provider = null;
+ }
+ }
+
+ [TestCaseSource(nameof(_timeoutTestCases))]
+ public void TestIdleTimeoutIsPassedOnlyIfNotNegative(int
configuredIdleTimeout, uint expectedIdleTimeOut)
+ {
+ var nmsConnectionInfo = new NmsConnectionInfo(new
NmsConnectionId("mock"));
+ nmsConnectionInfo.IdleTimeOut = configuredIdleTimeout;
+ connection = new AmqpConnection(provider, null, nmsConnectionInfo);
+ var open = new Open();
+ connection.OnLocalOpen(open);
+ Assert.AreEqual(open.IdleTimeOut, expectedIdleTimeOut);
+ }
+
+ private static object[] _timeoutTestCases =
+ [
+ new object[] { int.MaxValue, 2147483647u },
+ new object[] { int.MinValue, 0u },
+ new object[] { 123, 123u },
+ new object[] { 0, 0u },
+ new object[] { -1, 0u },
+ new object[] { -23, 0u }
+ ];
+
+ private Uri GetDefaultUri()
+ {
+ return new Uri("amqp://localhost:5672");
+ }
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact