[Bug 65763] New: WsRemoteEndpointImplBase#sendMessageBlock cannot close session properly when have TimeoutException

2021-12-23 Thread bugzilla
https://bz.apache.org/bugzilla/show_bug.cgi?id=65763

Bug ID: 65763
   Summary: WsRemoteEndpointImplBase#sendMessageBlock cannot close
session properly when have TimeoutException
   Product: Tomcat 9
   Version: 9.0.44
  Hardware: PC
OS: Mac OS X 10.1
Status: NEW
  Severity: normal
  Priority: P2
 Component: WebSocket
  Assignee: dev@tomcat.apache.org
  Reporter: qintai@oceanbase.com
  Target Milestone: -

Firstly, I found this exception:   

java.io.IOException: java.util.concurrent.TimeoutException
at
org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendMessageBlock(WsRemoteEndpointImplBase.java:324)
at
org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendMessageBlock(WsRemoteEndpointImplBase.java:259)
at 


It happens in
org.apache.tomcat.websocket.WsRemoteEndpointImplBase#sendMessageBlock(byte,
java.nio.ByteBuffer, boolean, long):
###java
if (!bsh.getSendResult().isOK()) {
messagePartInProgress.release();
Throwable t = bsh.getSendResult().getException();
wsSession.doClose(new CloseReason(CloseCodes.GOING_AWAY,
t.getMessage()),
new CloseReason(CloseCodes.CLOSED_ABNORMALLY,
t.getMessage()), true);
throw new IOException (t);
}
###

Actually, it is caused by
org.apache.tomcat.websocket.WsRemoteEndpointImplClient#doWrite which has a
LongToIntegerFuture.get timeout exception: 
###java
try {
channel.write(byteBuffer).get(timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException |
TimeoutException e) {
handler.onResult(new SendResult(e));
return;
}
###

But "writing" value is not set to "false" which has been set "true" in
org.apache.tomcat.websocket.AsyncChannelWrapperSecure#write(java.nio.ByteBuffer).
Only in org.apache.tomcat.websocket.AsyncChannelWrapperSecure.WriteTask,
"writing" will be reset to "false", but WriteTask may not finish when
LongToIntegerFuture.get timeout happens. This problem may like
https://bz.apache.org/bugzilla/show_bug.cgi?id=61003, but writing.set(false)
doesn't work in this timeout situation.  

When WsRemoteEndpointImplBase#sendMessageBlock get TimeoutException, it will
try to close session, see "wsSession.doClose(new
CloseReason(CloseCodes.GOING_AWAY, t.getMessage())". 

This method "wsSession.doClose" will set state = State.OUTPUT_CLOSED and send a
close message (org.apache.tomcat.websocket.WsSession#sendCloseMessage). But it
will case exception, because "writing" value is still "true":  
###
Caused by: java.lang.IllegalStateException: Concurrent write operations are
not permitted
at
org.apache.tomcat.websocket.AsyncChannelWrapperSecure.write(AsyncChannelWrapperSecure.java:117)
at
org.apache.tomcat.websocket.WsRemoteEndpointImplClient.doWrite(WsRemoteEndpointImplClient.java:62)
at
org.apache.tomcat.websocket.WsRemoteEndpointImplBase$OutputBufferSendHandler.write(WsRemoteEndpointImplBase.java:893)
at
org.apache.tomcat.websocket.WsRemoteEndpointImplBase.writeMessagePart(WsRemoteEndpointImplBase.java:506)
at
org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendMessageBlock(WsRemoteEndpointImplBase.java:311)
at
org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendMessageBlock(WsRemoteEndpointImplBase.java:259)
at
org.apache.tomcat.websocket.WsSession.sendCloseMessage(WsSession.java:613)
at org.apache.tomcat.websocket.WsSession.doClose(WsSession.java:498)
at
org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendMessageBlock(WsRemoteEndpointImplBase.java:322)
###

In org.apache.tomcat.websocket.WsSession#sendCloseMessage, it doesn't catch
IllegalStateException and close websocket channel: 
###java
try {
wsRemoteEndpoint.sendMessageBlock(Constants.OPCODE_CLOSE, msg,
true);
} catch (IOException | WritePendingException e) {
// Failed to send close message. Close the socket and let the
caller
// deal with the Exception
if (log.isDebugEnabled()) {
log.debug(sm.getString("wsSession.sendCloseFail", id), e);
}
wsRemoteEndpoint.close();
###

And this session may cannot be closed again because state has been set to
"OUTPUT_CLOSED".

I think IllegalStateException should be caught in
org.apache.tomcat.websocket.WsSession#sendCloseMessage or a better way to close
session when timeout happens.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[Bug 65763] WsRemoteEndpointImplBase#sendMessageBlock cannot close session properly when have TimeoutException

2021-12-23 Thread bugzilla
https://bz.apache.org/bugzilla/show_bug.cgi?id=65763

--- Comment #1 from alex  ---
Created attachment 38141
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=38141&action=edit
Caused by: java.lang.IllegalStateException: Concurrent write

-- 
You are receiving this mail because:
You are the assignee for the bug.
-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[Bug 65763] WsRemoteEndpointImplBase#sendMessageBlock cannot close session properly when have TimeoutException

2021-12-23 Thread bugzilla
https://bz.apache.org/bugzilla/show_bug.cgi?id=65763

--- Comment #2 from alex  ---
Comment on attachment 38141
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=38141
Caused by: java.lang.IllegalStateException: Concurrent write

>
>Caused by: java.lang.IllegalStateException: Concurrent write operations 
> are not permitted
>   at 
> org.apache.tomcat.websocket.AsyncChannelWrapperSecure.write(AsyncChannelWrapperSecure.java:117)
>   at 
> org.apache.tomcat.websocket.WsRemoteEndpointImplClient.doWrite(WsRemoteEndpointImplClient.java:62)
>   at 
> org.apache.tomcat.websocket.WsRemoteEndpointImplBase$OutputBufferSendHandler.write(WsRemoteEndpointImplBase.java:893)
>   at 
> org.apache.tomcat.websocket.WsRemoteEndpointImplBase.writeMessagePart(WsRemoteEndpointImplBase.java:506)
>   at 
> org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendMessageBlock(WsRemoteEndpointImplBase.java:311)
>   at 
> org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendMessageBlock(WsRemoteEndpointImplBase.java:259)
>   at 
> org.apache.tomcat.websocket.WsSession.sendCloseMessage(WsSession.java:613)
>   at org.apache.tomcat.websocket.WsSession.doClose(WsSession.java:498)
>   at 
> org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendMessageBlock(WsRemoteEndpointImplBase.java:322)
>   at 
> org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendMessageBlock(WsRemoteEndpointImplBase.java:251)
>   at 
> org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendPartialString(WsRemoteEndpointImplBase.java:224)
>   at 
> org.apache.tomcat.websocket.WsRemoteEndpointBasic.sendText(WsRemoteEndpointBasic.java:49)
>   at 
> org.springframework.web.socket.adapter.standard.StandardWebSocketSession.sendTextMessage(StandardWebSocketSession.java:215)
>   at 
> org.springframework.web.socket.adapter.AbstractWebSocketSession.sendMessage(AbstractWebSocketSession.java:106)
>   at 
> org.springframework.web.socket.sockjs.client.WebSocketClientSockJsSession.sendInternal(WebSocketClientSockJsSession.java:121)
>   at 
> org.springframework.web.socket.sockjs.client.AbstractClientSockJsSession.sendMessage(AbstractClientSockJsSession.java:162)

-- 
You are receiving this mail because:
You are the assignee for the bug.
-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[Bug 65757] Async WriteListener#onWritePossible never called

2021-12-23 Thread bugzilla
https://bz.apache.org/bugzilla/show_bug.cgi?id=65757

--- Comment #8 from Remy Maucherat  ---
(In reply to Mark Thomas from comment #7)
> (In reply to Remy Maucherat from comment #5)
> > Once reviewed and validated (if needed), a fix like this one is almost
> > always applied to all branches.
> 
> LGTM.
> 
> My only thought is how many of the other container thread checks really
> should be converted to this new request thread check.

Not sure.

When upgrading, there's no async context, so the calls there should be ok. Not
certain about the async state machine used through the Servlet container. The
scenario from the test is clearly the most common use (and I don't consider it
to be a great idea ;) ).

-- 
You are receiving this mail because:
You are the assignee for the bug.
-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[Bug 65755] Users sporadically receive responses intended for other user's session

2021-12-23 Thread bugzilla
https://bz.apache.org/bugzilla/show_bug.cgi?id=65755

--- Comment #1 from Christopher Schultz  ---
Usually this kind of thing is caused by an application retaining references to
object references like the session, request, or response.

Can you please confirm that you are not keeping any references to any of these
types of objects?

Are you using any long-running processes that are outside of the "normal"
servlet access pattern like request -> servlet -> response? For example, are
you using Websocket or "servlet async" features?

Are you able to upgrade to the latest Tomcat (8.5.73) just in case something
has been fixed?

-- 
You are receiving this mail because:
You are the assignee for the bug.
-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[tomcat] branch main updated: Update OWB and CXF example modules version numbers

2021-12-23 Thread remm
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 f52fde3  Update OWB and CXF example modules version numbers
f52fde3 is described below

commit f52fde372b0a68c09e0f60a7d8c9ac14f6421ac6
Author: remm 
AuthorDate: Thu Dec 23 15:57:36 2021 +0100

Update OWB and CXF example modules version numbers
---
 modules/cxf/pom.xml|  4 ++--
 modules/owb/pom.xml|  4 ++--
 webapps/docs/changelog.xml | 10 ++
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/modules/cxf/pom.xml b/modules/cxf/pom.xml
index a210ea9..0de6090 100644
--- a/modules/cxf/pom.xml
+++ b/modules/cxf/pom.xml
@@ -29,14 +29,14 @@
 Apache CXF for Apache Tomcat CDI
 Apache CXF packaged for Apache Tomcat CDI
 
-3.4.4
+3.5.0
 jar
 
 
 1.3
 1.1.4
 1.0
-1.2.12
+1.2.15
 
 
 
diff --git a/modules/owb/pom.xml b/modules/owb/pom.xml
index e6ac668..6c5c9bc 100644
--- a/modules/owb/pom.xml
+++ b/modules/owb/pom.xml
@@ -29,14 +29,14 @@
 Apache Tomcat CDI 2 support
 Apache Tomcat CDI 2 support using Apache 
OpenWebBeans
 
-2.0.23
+2.0.25
 jar
 
 
 1.2
 1.2
 1.3
-10.0.7
+10.0.14
 
 
 
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index bcc9d24..1e3a153 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -169,6 +169,16 @@
   
 
   
+  
+
+  
+Update the OWB module to Apache OpenWebBeans 2.0.25. (remm)
+  
+  
+Update the CXF module to Apache CXF 3.5.0. (remm)
+  
+
+  
 
 
   

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[tomcat] branch 10.0.x updated: Update OWB and CXF example modules version numbers

2021-12-23 Thread remm
This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch 10.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.0.x by this push:
 new dc2480c  Update OWB and CXF example modules version numbers
dc2480c is described below

commit dc2480ccca5cb6932bd05d22b82c89147e6c2441
Author: remm 
AuthorDate: Thu Dec 23 15:57:36 2021 +0100

Update OWB and CXF example modules version numbers
---
 modules/cxf/pom.xml|  4 ++--
 modules/owb/pom.xml|  4 ++--
 webapps/docs/changelog.xml | 10 ++
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/modules/cxf/pom.xml b/modules/cxf/pom.xml
index a210ea9..0de6090 100644
--- a/modules/cxf/pom.xml
+++ b/modules/cxf/pom.xml
@@ -29,14 +29,14 @@
 Apache CXF for Apache Tomcat CDI
 Apache CXF packaged for Apache Tomcat CDI
 
-3.4.4
+3.5.0
 jar
 
 
 1.3
 1.1.4
 1.0
-1.2.12
+1.2.15
 
 
 
diff --git a/modules/owb/pom.xml b/modules/owb/pom.xml
index 03f8571..6c5c9bc 100644
--- a/modules/owb/pom.xml
+++ b/modules/owb/pom.xml
@@ -29,14 +29,14 @@
 Apache Tomcat CDI 2 support
 Apache Tomcat CDI 2 support using Apache 
OpenWebBeans
 
-2.0.23
+2.0.25
 jar
 
 
 1.2
 1.2
 1.3
-10.0.6
+10.0.14
 
 
 
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 1947dc9..3616ca4 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -140,6 +140,16 @@
   
 
   
+  
+
+  
+Update the OWB module to Apache OpenWebBeans 2.0.25. (remm)
+  
+  
+Update the CXF module to Apache CXF 3.5.0. (remm)
+  
+
+  
 
 
   

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[tomcat] branch 9.0.x updated: Update OWB and CXF example modules version numbers

2021-12-23 Thread remm
This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
 new 3abafc7  Update OWB and CXF example modules version numbers
3abafc7 is described below

commit 3abafc7fa83b8271748a532ce900d167bb614380
Author: remm 
AuthorDate: Thu Dec 23 15:57:36 2021 +0100

Update OWB and CXF example modules version numbers
---
 modules/cxf/pom.xml|  4 ++--
 modules/owb/pom.xml|  4 ++--
 webapps/docs/changelog.xml | 10 ++
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/modules/cxf/pom.xml b/modules/cxf/pom.xml
index cce64cc..4df9a4b 100644
--- a/modules/cxf/pom.xml
+++ b/modules/cxf/pom.xml
@@ -29,14 +29,14 @@
 Apache CXF for Apache Tomcat CDI
 Apache CXF packaged for Apache Tomcat CDI
 
-3.4.4
+3.5.0
 jar
 
 
 1.3
 1.1.4
 1.0
-1.2.12
+1.2.15
 
 
 
diff --git a/modules/owb/pom.xml b/modules/owb/pom.xml
index 06ae4ed..8979ce3 100644
--- a/modules/owb/pom.xml
+++ b/modules/owb/pom.xml
@@ -29,14 +29,14 @@
 Apache Tomcat CDI 2 support
 Apache Tomcat CDI 2 support using Apache 
OpenWebBeans
 
-2.0.23
+2.0.25
 jar
 
 
 1.2
 1.2
 1.3
-9.0.46
+9.0.56
 
 
 
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 507d27c..b78e11c 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -140,6 +140,16 @@
   
 
   
+  
+
+  
+Update the OWB module to Apache OpenWebBeans 2.0.25. (remm)
+  
+  
+Update the CXF module to Apache CXF 3.5.0. (remm)
+  
+
+  
 
 
   

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Re: Enable to "json stringify" access logs

2021-12-23 Thread Christopher Schultz

Romain,

On 12/18/21 14:28, Romain Manni-Bucau wrote:

I wonder if you would be interested in an access log "function" enabling to
make an access log element a valid json string.

Idea is to enable to have access logs patterns producing valid JSON
whatever the dynamic string content, maybe something like

"key":"jsonEscaped(%r)",

or more tomcat style:

"key":"%{json}r)",


If you tried that today, you'd get the value of the request attribute 
named "json". I think we need a different syntax.


The closest thing to this I see in the current configuration is 
specifying the date-format of a timestamp like this:


%{pattern}t where %{...}t gets you the end-of-request timestamp.

I think it's going to be ugly no matter what we do.

Maybe instead of putting the escaping in the pattern, we could put the 
type of escaping into another attribute like this:




Then, when any %{...}? replacement will be done, it can be JSON-escaped. 
Any literal text in the pattern itself is up to the admin; specifically, 
it will not have any escaping applied to the pattern text, only the 
replacements.



What do you think? Is it worth proposing something or is it always handled
differently in your opinion (I tend to workaround it today so not 100% sure
it would be accepted if I do a PR)?


Actually, this could easily be done by subclassing AccessLogValve and 
overriding AbstractAccessLogValve.escapeAndAppend to provide the proper 
escaping.


I'd be +1 on accepting a JSONAccessLogValve class.

-chris


Another location which would benefit from some json encoding
is org.apache.catalina.valves.JsonErrorReportValve#report since currently
it produces invalid json depending the message value.

Romain Manni-Bucau
@rmannibucau  |  Blog
 | Old Blog
 | Github  |
LinkedIn  | Book




-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org