FileDownloader and Google App Engine Not Working

I’ve been playing around with FileDownloader and GAE for several days now and I’m pretty sure there’s a bug somewhere, although I haven’t been able to track it down exactly.

A lot of times, a first download works, sometimes two, sometimes three, but all eventually end in either a “Communication problem” with no message, or a DetachUIException or something like “RPC call received for connector but no such connector could be found. Resynchronizing client”.

I have tried any number of approaches including using David Wall’s OnDemandBrowserWindowOpener approach from https://vaadin.com/forum/#!/thread/4843509, Visruth CVs approach from https://vaadin.com/forum#!/thread/3329519 (in the hope that having a before an after download listener enabled me to figure out what the problem is), and the UIExecutor framework from https://vaadin.com/forum/#!/thread/4269500 as well as trying to isolate some or all parts of code with accessSynchronously.

Here’s a minimal view that causes the problem after a successful download and you navigate to a different view and come back.

import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.server.FileDownloader;
import com.vaadin.server.StreamResource;
import com.vaadin.ui.Button;
import com.vaadin.ui.VerticalLayout;
import org.apache.commons.io.input.ReaderInputStream;

import java.io.InputStream;
import java.io.StringReader;

public class Minimal extends VerticalLayout implements View {

    String csv = "email,firstName,lastName\nadmin@admin.com,,";

    public Minimal() {
        setSpacing(true);
        setMargin(true);
    }

    @Override
    public void enter(ViewChangeListener.ViewChangeEvent event) {
        removeAllComponents();
        Button db = new Button("Download");
        addComponent(db);
        db.setDisableOnClick(true);

        FileDownloader fd = new FileDownloader(new StreamResource(new StreamResource.StreamSource() {
            public InputStream getStream() {
                return new ReaderInputStream(new StringReader(csv));
            }
        }, "test.csv"));
        fd.extend(db);
    }
}

I have tried any number of attempts to make sure all resources are properly released before the next download is triggered. For example, making sure the FileDownloader extension is removed from the button and all components are emptied from the view, in beforeViewChange of a ViewChangeListener. The FileDownloader was also in a Tab of a TabSheet and a SelectedTabChangeListener made sure all resources were released.

If you go to this view, then leave, something is not right such that pretty soon, as you move among other views or return to this view and do another download, you end up with a crash.

Any thoughts would be greatly appreciated.

Jonathan