Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chromium is not closed completely gracefully #839

Closed
vsemozhetbyt opened this issue Sep 21, 2017 · 10 comments
Closed

Chromium is not closed completely gracefully #839

vsemozhetbyt opened this issue Sep 21, 2017 · 10 comments

Comments

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Sep 21, 2017

  • Puppeteer version: v0.11.0-alpha
  • Platform / OS version: Windows 7 x64

When I launch the Chromium with something like this

    const browser = await puppeteer.launch({
      headless: false,
      userDataDir: `${__dirname}/profile-dir`,
    });

every non-first launch this non-blocking dialog appears:

restore-pages

despite using await browser.close();

I am not sure if this is wontfix. Please, close the issue if it is.

@Garbee
Copy link
Contributor

Garbee commented Sep 21, 2017

  userDataDir: `${__dirname}/profile-dir`,

You aren't generating a unique profile on load. So this can trigger the dialog. Not sure if anything can be done about that within Chrome, especially with the new session restore system. Since the CLI flags to prevent this bubble were removed.

@vsemozhetbyt
Copy link
Contributor Author

vsemozhetbyt commented Sep 21, 2017

You aren't generating a unique profile on load.

Yes, this is the goal: I run some periodic task for ~600 URLs and need to use the cache. If using a saved profile is the aim of this option, the dialog is somewhat unexpectable for the user. Is not an emulation of common graceful exit possible for DevTools Protocol?

@Garbee
Copy link
Contributor

Garbee commented Sep 21, 2017

I'd need to see the exact script. This should just work as far as I have seen.

@vsemozhetbyt
Copy link
Contributor Author

vsemozhetbyt commented Sep 21, 2017

@Garbee My real script is rather long, but I can reproduce with this simplified version:

'use strict';

const puppeteer = require('puppeteer');

(async function main() {
  try {
    const browser = await puppeteer.launch({
      headless: false,
      userDataDir: `${__dirname}/profile-dir`,
    });
    const page = await browser.newPage();

    await page.goto('https://www.nytimes.com/');

    await page.waitFor(1000);

    await browser.close();
  } catch (err) {
    console.error(err);
  }
})();

If I use some very light page (say, http://example.org/), the dialog does not appear in non-first lunches. But with a heavy page like https://www.nytimes.com/ you can see it in non-first lunches.

@aslushnikov
Copy link
Contributor

@vsemozhetbyt I can't repro this on Mac. However, if you can repro this, would you mind checking if changing 'close' event to 'exit' in Launcher.js:90 help you? We might be exitting too early.

@JoelEinbinder, would you have a chance to try reproducing this?

@vsemozhetbyt
Copy link
Contributor Author

@aslushnikov Unfortunately, changing 'close' event to 'exit' does not prevent this dialog.

@aslushnikov
Copy link
Contributor

@vsemozhetbyt could you please also check if using taskkill instead of chromeProcess.kill will help? This would require changing Launcher.js:130 to be:

childProcess.execSync(`taskkill /pid ${chromeProcess.pid} /T`);

@vsemozhetbyt
Copy link
Contributor Author

vsemozhetbyt commented Sep 25, 2017

@aslushnikov This throws without closing the browser:

output:
ERROR: The process with PID 4988 (child process of PID 7012) could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
ERROR: The process with PID 3364 (child process of PID 7012) could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
ERROR: The process with PID 624 (child process of PID 7012) could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
ERROR: The process with PID 7012 (child process of PID 1520) could not be terminated.
Reason: One or more child processes of this process were still running.
{ Error: Command failed: taskkill /pid 7012 /T
ERROR: The process with PID 4988 (child process of PID 7012) could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
ERROR: The process with PID 3364 (child process of PID 7012) could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
ERROR: The process with PID 624 (child process of PID 7012) could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
ERROR: The process with PID 7012 (child process of PID 1520) could not be terminated.
Reason: One or more child processes of this process were still running.

    at checkExecSyncError (child_process.js:591:13)
    at Object.execSync (child_process.js:631:13)
    at killChrome (e:\DOC\prg\js\node\node_modules\puppeteer\lib\Launcher.js:130:24)
    at Browser.close (e:\DOC\prg\js\node\node_modules\puppeteer\lib\Browser.js:61:31)
    at main (e:\DOC\prg\js\node\-test\test.js:35:19)
    at <anonymous>
  error: null,
  cmd: 'taskkill /pid 7012 /T',
  file: 'C:\\Windows\\system32\\cmd.exe',
  args:
   [ 'C:\\Windows\\system32\\cmd.exe',
     '/d',
     '/s',
     '/c',
     '"taskkill /pid 7012 /T"' ],
  options:
   { shell: true,
     windowsVerbatimArguments: true,
     file: 'C:\\Windows\\system32\\cmd.exe',
     args:
      [ 'C:\\Windows\\system32\\cmd.exe',
        '/d',
        '/s',
        '/c',
        '"taskkill /pid 7012 /T"' ],
     envPairs:
      [ '#UE#FNI#=',
        'ALLUSERSPROFILE=C:\\ProgramData',
        'APPDATA=C:\\Users\\vmb\\AppData\\Roaming',
        'CommonProgramFiles=C:\\Program Files\\Common Files',
        'CommonProgramFiles(x86)=C:\\Program Files (x86)\\Common Files',
        'CommonProgramW6432=C:\\Program Files\\Common Files',
        'COMPUTERNAME=VMB-NB',
        'ComSpec=C:\\Windows\\system32\\cmd.exe',
        'FP_NO_HOST_CHECK=NO',
        'HOMEDRIVE=C:',
        'HOMEPATH=\\Users\\vmb',
        'LOCALAPPDATA=C:\\Users\\vmb\\AppData\\Local',
        'LOGONSERVER=\\\\VMB-NB',
        'NUMBER_OF_PROCESSORS=4',
        'OS=Windows_NT',
        'Path=C:\\Program Files\\IDM Computer Solutions\\UltraEdit\\;C:\\Python27\\;C:\\Python27\\Scripts;C:\\Program Files\\Broadcom\\Broadcom 802.11 Network Adapter\\Driver;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\IDM Computer Solutions\\UltraEdit;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;C:\\Program Files (x86)\\Common Files\\Acronis\\SnapAPI\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\Git\\mingw64\\bin;C:\\Program Files\\Git\\usr\\bin;C:\\Program Files\\nodejs\\;C:\\Users\\vmb\\AppData\\Roaming\\npm',
        'PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC',
        'PROCESSOR_ARCHITECTURE=AMD64',
        'PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 37 Stepping 5, GenuineIntel',
        'PROCESSOR_LEVEL=6',
        'PROCESSOR_REVISION=2505',
        'ProgramData=C:\\ProgramData',
        'ProgramFiles=C:\\Program Files',
        'ProgramFiles(x86)=C:\\Program Files (x86)',
        'ProgramW6432=C:\\Program Files',
        'PROMPT=$P$G',
        'PSModulePath=C:\\Program Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules',
        'PUBLIC=C:\\Users\\Public',
        'SESSIONNAME=Console',
        'SystemDrive=C:',
        'SystemRoot=C:\\Windows',
        'TEMP=c:\\Windows\\Temp',
        'TMP=c:\\Windows\\Temp',
        'UeApp=UltraEdit',
        'UEHELPATH=C:\\Program Files\\IDM Computer Solutions\\UltraEdit\\uedit64.chm',
        'UESPropEffect=',
        'USERDOMAIN=VMB-NB',
        'USERNAME=vmb',
        'USERPROFILE=C:\\Users\\vmb',
        'VS140COMNTOOLS=C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Tools\\',
        'windir=C:\\Windows',
        'windows_tracing_flags=3',
        'windows_tracing_logfile=C:\\BVTBin\\Tests\\installpackage\\csilogfile.log',
        '__COMPAT_LAYER=DisableUserCallbackException' ],
     killSignal: undefined,
     stdio: [ [Object], [Object], [Object] ] },
  envPairs:
   [ '#UE#FNI#=',
     'ALLUSERSPROFILE=C:\\ProgramData',
     'APPDATA=C:\\Users\\vmb\\AppData\\Roaming',
     'CommonProgramFiles=C:\\Program Files\\Common Files',
     'CommonProgramFiles(x86)=C:\\Program Files (x86)\\Common Files',
     'CommonProgramW6432=C:\\Program Files\\Common Files',
     'COMPUTERNAME=VMB-NB',
     'ComSpec=C:\\Windows\\system32\\cmd.exe',
     'FP_NO_HOST_CHECK=NO',
     'HOMEDRIVE=C:',
     'HOMEPATH=\\Users\\vmb',
     'LOCALAPPDATA=C:\\Users\\vmb\\AppData\\Local',
     'LOGONSERVER=\\\\VMB-NB',
     'NUMBER_OF_PROCESSORS=4',
     'OS=Windows_NT',
     'Path=C:\\Program Files\\IDM Computer Solutions\\UltraEdit\\;C:\\Python27\\;C:\\Python27\\Scripts;C:\\Program Files\\Broadcom\\Broadcom 802.11 Network Adapter\\Driver;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\IDM Computer Solutions\\UltraEdit;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;C:\\Program Files (x86)\\Common Files\\Acronis\\SnapAPI\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\Git\\mingw64\\bin;C:\\Program Files\\Git\\usr\\bin;C:\\Program Files\\nodejs\\;C:\\Users\\vmb\\AppData\\Roaming\\npm',
     'PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC',
     'PROCESSOR_ARCHITECTURE=AMD64',
     'PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 37 Stepping 5, GenuineIntel',
     'PROCESSOR_LEVEL=6',
     'PROCESSOR_REVISION=2505',
     'ProgramData=C:\\ProgramData',
     'ProgramFiles=C:\\Program Files',
     'ProgramFiles(x86)=C:\\Program Files (x86)',
     'ProgramW6432=C:\\Program Files',
     'PROMPT=$P$G',
     'PSModulePath=C:\\Program Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules',
     'PUBLIC=C:\\Users\\Public',
     'SESSIONNAME=Console',
     'SystemDrive=C:',
     'SystemRoot=C:\\Windows',
     'TEMP=c:\\Windows\\Temp',
     'TMP=c:\\Windows\\Temp',
     'UeApp=UltraEdit',
     'UEHELPATH=C:\\Program Files\\IDM Computer Solutions\\UltraEdit\\uedit64.chm',
     'UESPropEffect=',
     'USERDOMAIN=VMB-NB',
     'USERNAME=vmb',
     'USERPROFILE=C:\\Users\\vmb',
     'VS140COMNTOOLS=C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Tools\\',
     'windir=C:\\Windows',
     'windows_tracing_flags=3',
     'windows_tracing_logfile=C:\\BVTBin\\Tests\\installpackage\\csilogfile.log',
     '__COMPAT_LAYER=DisableUserCallbackException' ],
  stderr: <Buffer 45 52 52 4f 52 3a 20 54 68 65 20 70 72 6f 63 65 73 73 20 77 69 74 68 20 50 49 44 20 34 39 38 38 20 28 63 68 69 6c 64 20 70 72 6f 63 65 73 73 20 6f 66 ... >,
  stdout: <Buffer 53 55 43 43 45 53 53 3a 20 53 65 6e 74 20 74 65 72 6d 69 6e 61 74 69 6f 6e 20 73 69 67 6e 61 6c 20 74 6f 20 70 72 6f 63 65 73 73 20 77 69 74 68 20 50 ... >,
  pid: 5464,
  output:
   [ null,
     <Buffer 53 55 43 43 45 53 53 3a 20 53 65 6e 74 20 74 65 72 6d 69 6e 61 74 69 6f 6e 20 73 69 67 6e 61 6c 20 74 6f 20 70 72 6f 63 65 73 73 20 77 69 74 68 2050 ... >,
     <Buffer 45 52 52 4f 52 3a 20 54 68 65 20 70 72 6f 63 65 73 73 20 77 69 74 68 20 50 49 44 20 34 39 38 38 20 28 63 68 69 6c 64 20 70 72 6f 63 65 73 73 20 6f66 ... > ],
  signal: null,
  status: 128 }

@aslushnikov
Copy link
Contributor

@vsemozhetbyt one last experiment:

childProcess.execSync(`taskkill /pid ${chromeProcess.pid} >nul`);

(as suggested by superuser post)

@vsemozhetbyt
Copy link
Contributor Author

@aslushnikov This one seems to prevent the dialog. Thank you!

aslushnikov added a commit to aslushnikov/puppeteer that referenced this issue Sep 26, 2017
This patch starts using `taskkill` program on windows to gracefully
terminate chrome.

Fixes puppeteer#839.
aslushnikov added a commit that referenced this issue Sep 29, 2017
This patch starts using taskkill program on windows to gracefully
terminate chrome.

Note: this slows down chrome shutdown on Windows in case of using
custom userDataDir. This is because chrome takes some time to shutdown
its operations and leave profile directory in a consistent state.

Fixes #839.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants