vaadin / multiplatform-runtime

4 stars 1 forks source link

Bug in file upload handling thread: may lose v21 session. #94

Open enver-haase opened 2 years ago

enver-haase commented 2 years ago

16:16:25.171 [http-nio-8080-exec-2] ERROR com.daimler.pariss.ui.util.I18nHandler - Retrieving locale, Session 8 is 'com.vaadin.mpr.core.MprSession@1376308843'; Session21 is 'com.vaadin.flow.spring.SpringVaadinSession@2054761651'. 16:16:25.171 [http-nio-8080-exec-2] ERROR com.xxx.ui.util.I18nHandler - Retrieving locale, Session 8 is 'com.vaadin.mpr.core.MprSession@1376308843'; Session21 is 'com.vaadin.flow.spring.SpringVaadinSession@2054761651'. 16:16:28.541 [http-nio-8080-exec-4] ERROR com.xxx.ui.component.AttachmentDialog - Upload failed: java.lang.NullPointerException. UI is com.vaadin.mpr.MprUI@-2019629932, Session is com.vaadin.mpr.core.MprSession@1376308843 16:16:28.541 [http-nio-8080-exec-4] ERROR com.xxx.ui.util.I18nHandler - Retrieving locale, Session 8 is 'com.vaadin.mpr.core.MprSession@1376308843'; Session21 is 'null'. 16:16:28.549 [http-nio-8080-exec-4] ERROR com.vaadin.server.DefaultErrorHandler - java.lang.NullPointerException: null at com.xxx.ui.util.I18nHandler.getLocale(I18nHandler.java:156) at com.xxx.ui.util.I18nHandler.getResourceBundle(I18nHandler.java:37) at com.xxx.ui.util.I18nHandler.getMessage(I18nHandler.java:60) at com.xxx.ui.component.AttachmentDialog$1.streamingFailed(AttachmentDialog.java:217) at com.vaadin.ui.dnd.FileDropTarget$FileReceiver.streamingFailed(FileDropTarget.java:226) at com.vaadin.server.communication.FileUploadHandler.streamToReceiver(FileUploadHandler.java:639) at com.vaadin.server.communication.FileUploadHandler.handleFileUploadValidationAndData(FileUploadHandler.java:469)

enver-haase commented 2 years ago

Above debug output is generated by using com.vaadin.server.VaadinSession.getCurrent() for v8 com.vaadin.flow.server.VaadinSession.getCurrent() for v21

enver-haase commented 2 years ago

As is said in the headline -- this does not always happen. Only often.

denis-anisimov commented 2 years ago

Hello, thanks for the report. Can you please provide an example project based on that reproduces the issue ? Otherwise there is not much what we can do with this.

TatuLund commented 2 years ago

This could be related to https://github.com/vaadin/multiplatform-runtime/issues/95

I am working on two or three cases where session gets oddly lost. This leads to e.g. NPEs in different parts of the MPR code flow.

enver-haase commented 2 years ago

I wonder why you cannot do much about this -- the setup is as follows: v8 view in an MprRouteAdapter, all running in V21 with Spring Boot, and obviously from the stacktrace we're talking about the call-back thread from a V8 file upload that is missing it's V21 session.

denis-anisimov commented 2 years ago

Can you please provide a simple project which demoes how I can reproduce this ? Apparently it's obvious for you but I'm not familiar with MPR at all so I don't see what's involved here.

enver-haase commented 2 years ago

There is no 'simple' MPR project, as setting any MPR project up would probably take a couple of hours. I can however share a not-so-simple project, or we can have a screen-sharing session.

enver-haase commented 2 years ago

package com.xxx.pariss.ui.component;

import org.slf4j.Logger; import org.slf4j.LoggerFactory;

import com.xxx.pariss.app.ApplicationServiceInitListener; import com.vaadin.flow.server.VaadinSession;

public class RepairSession {

 private final static Logger log = LoggerFactory.getLogger(RepairSession.class);
/**
 * Let a call-back thread (e.g. from Vaadin file upload) call into this.
 * @param knownGoodSession the Vaadin session that was carried by the thread setting up the call-back hooks.
 */
public static void repairSession(VaadinSession knownGoodSession){
    log.debug("This is working around an MPR defect: https://github.com/vaadin/multiplatform-runtime/issues/94");
    VaadinSession apparentSession = VaadinSession.getCurrent();
    if (knownGoodSession != null){
        if (apparentSession == null){
            VaadinSession.setCurrent(knownGoodSession);
            log.warn("Applied a hotfix: set '"+ApplicationServiceInitListener.getIdentifier(knownGoodSession)+"' as the call-back thread had a NULL session.");
        }
        else if (VaadinSession.getCurrent() != knownGoodSession){
            log.warn("Set-up thread's session was '"+ ApplicationServiceInitListener.getIdentifier(knownGoodSession)+"', but call-back thread's session is '"+ApplicationServiceInitListener.getIdentifier(apparentSession)+"'.");
        }
    }
    else{
        log.error("Cannot apply work around -- the session to apply is NULL. Cannot do that sensibly.");
    }
}

}

enver-haase commented 2 years ago

the above code may help -- this is how the problem manifests