java Tomcat 会话意外过期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/959174/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 14:34:32  来源:igfitidea点击:

Tomcat sessions expiring unexpectedly

javasessiontomcat

提问by Bogdan Gusiev

We are running tomcat application server that handle over 100 concurrent sessions. In the last 2 months the most active users noticed that sometimes they are getting kicked off from the system.

我们正在运行能够处理 100 多个并发会话的 tomcat 应用程序服务器。在过去的 2 个月中,最活跃的用户注意到有时他们会被系统踢出。

As I understood from the log tomcat sessions are getting expired without any reason.

正如我从日志中了解到的,tomcat 会话无缘无故地过期了。

I see no problems from the web application side. Is there any problem from the tomcat side?

我认为 Web 应用程序方面没有问题。从tomcat方面有什么问题吗?

Tomcat 6.0.18.

雄猫 6.0.18。

采纳答案by Thorbj?rn Ravn Andersen

If there has been no code chance triggering this, I would look at memory usage. This mightbe the effect of Tomcat running out of memory and invalidating sessions to recover.

如果没有代码机会触发这个,我会看看内存使用情况。这可能是 Tomcat 内存不足和会话无效以恢复的影响。

If at all possible monitor garbage collections, and/or put surveillance on with jconsole or jvisualvm.

如果可能的话,监视垃圾收集,和/或使用 jconsole 或 jvisualvm 进行监视。

回答by idrosid

A possible cause is that you put in the session an object that does NOT implement the Serializable interface. Tomcat occasionally writes some of the sessions on the disk. If a session contains non-serializable objects it will simply be removed from the container (because of the NotSerializableException). If this is happening you should see the Exception in the tomcat log file.

一个可能的原因是您在会话中放置了一个未实现 Serializable 接口的对象。Tomcat 偶尔会在磁盘上写入一些会话。如果会话包含不可序列化的对象,它将简单地从容器中删除(因为 NotSerializableException)。如果发生这种情况,您应该会在 tomcat 日志文件中看到异常。

回答by David Rabinowitz

I would increase the monitoring of the server in general and the sessions specifically.

我会增加对服务器的监控,特别是对会话的监控。

A good monitoring application is lambda probe- it allows you to view the current sessions and their data. I would also add a HttpSessionListenerto log session creation and destruction.

一个很好的监控应用程序是lambda 探针- 它允许您查看当前会话及其数据。我还会添加一个HttpSessionListener来记录会话的创建和销毁。

Edit

编辑

Is is possible that you add some non serializble objects to the session and Tomcat fails to passivate them to the disk?

是否有可能将一些非序列化对象添加到会话中,而 Tomcat 无法将它们钝化到磁盘?

Edit 2

编辑 2

Lambda probe seems to be dead, and there a much better fork of the project over at http://code.google.com/p/psi-probe/

Lambda 探测器似乎已经死了,并且在http://code.google.com/p/psi-probe/ 上有更好的项目分支

回答by dfa

there is a timeout, that you can configure in your web.xml:

有一个超时,您可以在 web.xml 中配置:

<web-app>
  ...
  <session-config>
    <session-timeout>-1</session-timeout> 
  </session-config>
</web-app>

use -1 for no timeout

使用 -1 表示没有超时

回答by Pete Brumm

We just ran into this with tomcat 6_0_18 and ibm 1.5 jvm

我们刚刚用 tomcat 6_0_18 和 ibm 1.5 jvm 遇到了这个问题

turns out it was an ibm jvm issue with atomic operations.

原来这是一个带有原子操作的 ibm jvm 问题。

There is a fix in tomcats greater than 6_0_19 to handle it.

tomcats 中有一个大于 6_0_19 的修复程序来处理它。

It also doesn't occur in sun 1.5 jvm

它也不会发生在 sun 1.5 jvm 中

here are some more details

这里有更多细节

tomcat bugzilla case

tomcat bugzilla案例

回答by Andrew

I have seen similar problems when the following prerequisites exist:

当存在以下先决条件时,我看到了类似的问题:

  • multiple instances of the tomcat app are installed across multiple JVMs
  • load balancing (between the web server and the Tomcat JVMs) is not configured correctly.
  • Tomcat's session replication feature is notenabled
  • 跨多个 JVM 安装了多个 tomcat 应用程序实例
  • 负载平衡(在 Web 服务器和 Tomcat JVM 之间)配置不正确。
  • Tomcat的会话复制功能没有开启

Due to the incorrect load balancing config, the web server may randomly decide to break session affinity and send an incoming request to a Tomcat JVM that has never seen the session before. The Tomcat JVM will issue a new session and the user will lose all of their previouS session data and effectively start over.

由于负载平衡配置不正确,Web 服务器可能会随机决定中断会话关联并将传入请求发送到以前从未见过会话的 Tomcat JVM。Tomcat JVM 将发出一个新会话,用户将丢失所有以前的会话数据并有效地重新开始。

回答by Stu Thompson

Increase your logging of sessions, which may shed some light onto your problem.

增加您的会话记录,这可能会揭示您的问题。

The Tomcat config page's Logging in Tomcatincludes an example of increasing logging of sessions.

Tomcat 配置页面的Logging in Tomcat包括增加会话日志记录的示例。

回答by kgiannakakis

You can search Tomcat's bug database, but it would be better to have another look at your web application first. The chances that there is something wrong with Tomcat are very low.

您可以搜索 Tomcat 的错误数据库,但最好先查看您的 Web 应用程序。Tomcat 出现问题的可能性非常低。

Try to investigate what causes session invalidation. Are you using filters? Do you have cross-context requests? Try adding logging information for every request to find out, when exactly the session is lost.

尝试调查导致会话失效的原因。你在使用过滤器吗?你有跨上下文的请求吗?尝试为每个请求添加日志信息以找出会话丢失的确切时间。

回答by Sathya

Eventhough I do not know the cause of the problem, one possible fix (which I had done at my previous project) would be to run the application on a tomcat cluster and have session failover. Sessions can be by default sticky and when one node goes down, the healthy nodes pick up the sessions and all this is transparent to the end user.

尽管我不知道问题的原因,但一个可能的解决方法(我在之前的项目中已经做过)是在 tomcat 集群上运行应用程序并进行会话故障转移。默认情况下,会话可以是粘性的,当一个节点出现故障时,健康的节点会接续会话,所有这些对最终用户都是透明的。