login problem (server is randomly unresponsive for a very long time)

Hello vaadiners
its me again and the problem is still the same:

randomly the login proccess takes to long time (15 minutes)

my develepment environment::

  • tomcat 6
  • vaadin 6.6.3
  • postgresql (with a jdbc4 driver)

The scenario usally the following:

  • after I reload/restart my web application with tomcat’s manager application every thing works fine: login proccess is only matter of seconds
  • but after a few days of running suddenly the login procces takes VERY long time (15 mins)
  • if I restart the app with tomcats manager, then everything is ok again

here are some extract from my log files

if something goes wrong:


Aug 17, 2011 11:15:09 AM com.digicpictures.dproject.Dproject tryToLogIn
INFO: LOGIN ATTEMPT
username: petero
password: petero
Aug 17, 2011 11:30:47 AM com.digicpictures.dproject.Dproject tryToLogIn
INFO: valid username/password
Aug 17, 2011 11:30:47 AM com.digicpictures.dproject.Dproject tryToLogIn
INFO: user created/changed
Aug 17, 2011 11:30:48 AM com.digicpictures.dproject.Dproject tryToLogIn
INFO: END method


I also attach a screenshot to demonstrate this issue

if everything is ok:


Aug 17, 2011 11:47:18 AM com.digicpictures.dproject.Dproject tryToLogIn
INFO: LOGIN ATTEMPT
username: petero
password: petero
Aug 17, 2011 11:47:18 AM com.digicpictures.dproject.Dproject tryToLogIn
INFO: valid username/password
Aug 17, 2011 11:47:18 AM com.digicpictures.dproject.Dproject tryToLogIn
INFO: user created/changed
Aug 17, 2011 11:47:21 AM com.digicpictures.dproject.Dproject tryToLogIn
INFO: END method

I use vaadin and some addons from the directory (for example tpt)

I have one main window which consists of 2 parts:

  • one for the invisible components ( urifragmenthandler, sessionguard, etc)
  • and one container for the visible parts this containers content is changing dependent wether the user is logged in or not

And here are some relevant code samples from my application class:


public class Dproject extends TPTApplication implements FragmentChangedListener, UserChangeListener,
		HttpServletRequestListener {


@Override
	public void init() {
		
		super.init();
		this.addListener(this);
				
		initLoginCookies();
		setBrowserInfo();
		initUI();
		
		
		
		
		if (autoLogin) {
			String defaultUser = this.getProperty("defaultUser");
			String defaultPassword = this.getProperty("defaultPassword");
			tryToLogIn(defaultUser, defaultPassword, false);
		}
		
		else if (cookieUsername!=null && cookiePassword!=null){
			tryToLogIn(cookieUsername, cookiePassword, false);
			
		}

		else {
			if (this.getUser() == null) {
				// appWindow.setContent(getLoginWindow());
				visibleComponentsContainer.setContent(getLoginWindow());
			}

			else {
				visibleComponentsContainer.setContent(_getMainWindow());
			}
		}
		appWindowLayout.setExpandRatio(visibleComponentsContainer, 1);
		setTheme("digicpictures");

		

	}

public void initUI() {
		appWindow.setStyleName("app-window");
		appWindowLayout.setStyleName("app-window-layout");
		
		
		
		appWindowLayout.setSizeFull();
		appWindowLayout.setMargin(false);
		appWindowLayout.setSpacing(false);

		HorizontalLayout invisibleComponents = new HorizontalLayout();
		invisibleComponents.addStyleName("invisible-components");
		invisibleComponents.setStyleName(Reindeer.PANEL_LIGHT);

		invisibleComponents.addComponent(fragmentHandler);
		
		// invisibleComponents.addComponent(cookies);
		
		final SessionGuard sessionGuard = new SessionGuard();
		sessionGuard.setKeepalive(true);
	    invisibleComponents.addComponent(sessionGuard);
	    
		
		
	    visibleComponentsContainer.setStyleName(Reindeer.PANEL_LIGHT);
		visibleComponentsContainer.setSizeFull();

		appWindowLayout.addComponent(invisibleComponents);
		appWindowLayout.addComponent(visibleComponentsContainer);
		appWindowLayout.setExpandRatio(visibleComponentsContainer,1);

		fragmentHandler.addListener(this);
		// cookies.addListener(this);

		appWindow.setContent(appWindowLayout);
		this.setMainWindow(appWindow);
	}

	private void tryToLogIn(String email, String password,boolean rememberMe) {
		
		
		logger.info("LOGIN ATTEMPT\r\nusername: "+email+"\r\npassword: "+password);
		
		
		
		
		
		PreparedStatement pstmt = null;  
		  ResultSet rs = null;
		  Connection connection;
		try {
			connection=Dproject.getConnection();
			  
			  String pstmtSQL = "SELECT dpc_id,dpc_handle,dpc_name,dpc_loginname, dpc_language, dpc_accesslevel "
						        + "FROM  dpt_resource "
						        + "WHERE dpc_loginname=? "
						        + "AND dpc_password=md5(?)"
						        + "AND dpc_allow_web_access=true";
				
				pstmt = connection.prepareStatement(pstmtSQL);
				pstmt.setString(1, email);
				pstmt.setString(2, password);
				rs = pstmt.executeQuery();
				if (rs.next()) {
					userLoggedIn=true;
					
					logger.info("valid username/password");
					
					
					User user = new User(rs.getString("dpc_handle"), rs.getString("dpc_loginname"), rs.getString("dpc_name"));
					user.setAccesslevel(rs.getInt("dpc_accesslevel"));
					user.setLanguage(rs.getString("dpc_language"));
					logger.info("user created/changed");
					setUser(user);
										
					if (rememberMe) {
									 
						setLoginCookies(email, password);
					}


 
					
					


				}// if vége

				else {
					logger.info("INVALID username/password");
					getMainWindow().showNotification("Sikertelen bejelentkezés",LOGIN_ERROR_MSG, Notification.TYPE_WARNING_MESSAGE);
					
				}
		    rs.close();
		    rs = null;
		    pstmt.close();
		    pstmt = null;
		    
		    if (userLoggedIn && connection!=null) {
				connection.close(); // Return to connection pool
				connection = null; // Make sure we don't close it twice
				System.out.println("connection CLOSED in TRY block");
			}
		    
		    
		  }
		  catch (SQLException e) {
		   e.printStackTrace();
		  }
		 
		  
		  logger.info("END method");
		
	}// trylogin fv vége

What can cause this issue and how can I solve it (at least temporaryly)?

is there a better/ reccent solution for user authentication/authorization/login?

  • is it a browser-server communication issue?
  • is it a server side only issue?
  • is it a communication problem beetween the database and vaadin ( and if it is , how can I further debug it?)
  • is it a tomcat issue?
  • is it a database (postgresql 9) issue?
  • is there something wrong with my code?

Please help, this error simply drives me crazy :frowning:
11857.jpg

That’s a tough one. If it were me, I’d figure out exactly which call is taking so long (my guess would be the getConnection-call, but it could be the executeQuery call as well). I know that’s not exactly easy, with the delay of a few days. Try attaching a profiler to the jvm after the issue starts manifesting.

My first guesses would be memory leaks and/or connection pooling/timeout issues with the jdbc driver or database.