This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new d314df0a07 Tighten up thread safety d314df0a07 is described below commit d314df0a0701b7166445db4691036de17fb5d68e Author: remm <r...@apache.org> AuthorDate: Thu Aug 28 15:10:14 2025 +0200 Tighten up thread safety This feels not really needed since this scenario should most likely not happen (maybe some weird websockets ?), so keeping it to trunk only. Found by Coverity. --- .../apache/coyote/http11/upgrade/UpgradeInfo.java | 46 ++++++++++++++-------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/java/org/apache/coyote/http11/upgrade/UpgradeInfo.java b/java/org/apache/coyote/http11/upgrade/UpgradeInfo.java index ecce76d5f2..8b6a99014c 100644 --- a/java/org/apache/coyote/http11/upgrade/UpgradeInfo.java +++ b/java/org/apache/coyote/http11/upgrade/UpgradeInfo.java @@ -16,6 +16,8 @@ */ package org.apache.coyote.http11.upgrade; +import java.util.concurrent.atomic.LongAdder; + /** * Structure to hold statistical information about connections that have been established using the HTTP/1.1 upgrade * mechanism. Bytes sent/received will always be populated. Messages sent/received will be populated if that makes sense @@ -24,10 +26,10 @@ package org.apache.coyote.http11.upgrade; public class UpgradeInfo { private UpgradeGroupInfo groupInfo = null; - private volatile long bytesSent = 0; - private volatile long bytesReceived = 0; - private volatile long msgsSent = 0; - private volatile long msgsReceived = 0; + private final LongAdder bytesSent = new LongAdder(); + private final LongAdder bytesReceived = new LongAdder(); + private final LongAdder msgsSent = new LongAdder(); + private final LongAdder msgsReceived = new LongAdder(); public UpgradeGroupInfo getGlobalProcessor() { @@ -49,53 +51,65 @@ public class UpgradeInfo { public long getBytesSent() { - return bytesSent; + return bytesSent.longValue(); } public void setBytesSent(long bytesSent) { - this.bytesSent = bytesSent; + this.bytesSent.reset(); + if (bytesSent > 0) { + this.bytesSent.add(bytesSent); + } } public void addBytesSent(long bytesSent) { - this.bytesSent += bytesSent; + this.bytesSent.add(bytesSent); } public long getBytesReceived() { - return bytesReceived; + return bytesReceived.longValue(); } public void setBytesReceived(long bytesReceived) { - this.bytesReceived = bytesReceived; + this.bytesReceived.reset(); + if (bytesReceived > 0) { + this.bytesReceived.add(bytesReceived); + } } public void addBytesReceived(long bytesReceived) { - this.bytesReceived += bytesReceived; + this.bytesReceived.add(bytesReceived); } public long getMsgsSent() { - return msgsSent; + return msgsSent.longValue(); } public void setMsgsSent(long msgsSent) { - this.msgsSent = msgsSent; + this.msgsSent.reset(); + if (msgsSent > 0) { + this.msgsSent.add(msgsSent); + } } public void addMsgsSent(long msgsSent) { - this.msgsSent += msgsSent; + this.msgsSent.add(msgsSent); } public long getMsgsReceived() { - return msgsReceived; + return msgsReceived.longValue(); } public void setMsgsReceived(long msgsReceived) { - this.msgsReceived = msgsReceived; + this.msgsReceived.reset(); + if (msgsReceived > 0) { + this.msgsReceived.add(msgsReceived); + } } public void addMsgsReceived(long msgsReceived) { - this.msgsReceived += msgsReceived; + this.msgsReceived.add(msgsReceived); } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org