Skip to content
This repository has been archived by the owner on Feb 21, 2020. It is now read-only.

re-initialise chrome if disconnected #6

Merged
merged 3 commits into from
Jan 23, 2017
Merged

re-initialise chrome if disconnected #6

merged 3 commits into from
Jan 23, 2017

Conversation

yetti
Copy link
Contributor

@yetti yetti commented Jan 23, 2017

@ato Probably not the greatest way to do this, but at least the webapp will automatically reconnect to the webservice if it loses its connection (i.e. the headless-chromium service gets restarted).

String contextId;

private void init() throws IOException, TimeoutException, InterruptedException {
chrome = this.chrome = new Chropro("ws://" + this.chromeHost + ":" + this.chromePort + "/devtools/browser");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think chrome and this.chrome are the same field?

targetId = chrome.target.createTarget("about:blank", w, h, contextId).get(timeout, MILLISECONDS).targetId;
} catch (WebsocketNotConnectedException ex) {
System.out.println("Lost connection to web service. Re-initialising chrome client.");
init();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's race here if two requests come in while the connection is dead and both try to re-establish it. The first across the line will have their connection replaced and leak. Maybe we could mark init() as 'synchronized' and also call close on the connection that we're replacing?

That can still race but at least it'll just cause a temporary error rather than a connection leak.

* cleanup initialisation of chrome in init()
* mark init() as synchronised
* close connection before replacing it
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants