一、问题

在docker上跑Selenium+ChromeDriver+Chrome无头模式报错:

UnknownError: unknown error: session deleted because of page crash
from tab crashed
(Session info: chrome=43.0.2357.81)
(Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3),platform=Linux 3.13.0-32-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 53 milliseconds
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'zelenium', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-32-generic', java.version: '1.7.0_80'
Session ID: b12eb3c43351dad58746798c40078ef9
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/tmp/.com.google.Chrome.11yHIh}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=43.0.2357.81, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, applicationCacheEnabled=false, takesScreenshot=true}]

二、分析

/dev/shm太小了,要扩容

三、解决方案

3.1 如果环境是Kubernetes(k8s)请参考:Kubernetes(k8s) docker 修改 /dev/shm大小
3.2 如何修改/dev/shm大小?

/dev/shm在/etc/fstab中挂载,对应tmpfs,实际使用的是内存的空间。默认情况下,/dev/shm为物理内存大小的一半。因而,调整/dev/shm大小有两种方式:

  • 加大Linux的物理内存

  • 在/etc/fstab中明确指定/dev/shm的挂载sizes大小参数

[root@centos-fuwenchao mntsda3]# df -h /dev/shm
Filesystem            Size  Used Avail Use% Mounted on
tmpfs                 935M  228K  935M   1% /dev/shm
[root@centos-fuwenchao mntsda3]# vi /etc/fstab
      
      2 #
      3 # /etc/fstab
      4 # Created by anaconda on Fri Nov  1 21:18:42 2013
      5 #
      6 # Accessible filesystems, by reference, are maintained under '/dev/disk'
      7 # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
      8 #
      9 UUID=8e319772-a274-4031-a53f-1178b3ab4de6 /                       ext4    defaults        1 1
     10 UUID=ad4de750-9575-4040-a403-08c0642f0f2c swap                    swap    defaults        0 0
     11 tmpfs                   /dev/shm                tmpfs   defaults        0 0
     12 devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
     13 sysfs                   /sys                    sysfs   defaults        0 0
     14 proc                    /proc                   proc    defaults        0 0
[root@centos-fuwenchao mntsda3]# cp /etc/fstab /etc/fstab.20140218
[root@centos-fuwenchao mntsda3]# vi /etc/fstab
      1
      2 #
      3 # /etc/fstab
      4 # Created by anaconda on Fri Nov  1 21:18:42 2013
      5 #
      6 # Accessible filesystems, by reference, are maintained under '/dev/disk'
      7 # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
      8 #
      9 UUID=8e319772-a274-4031-a53f-1178b3ab4de6 /                       ext4    defaults        1 1
     10 UUID=ad4de750-9575-4040-a403-08c0642f0f2c swap                    swap    defaults        0 0
     11 tmpfs                   /dev/shm                tmpfs   defaults,size=1024M        0 0
     12 devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
     13 sysfs                   /sys                    sysfs   defaults        0 0
     14 proc                    /proc                   proc    defaults        0 0

重新挂载

[root@centos-fuwenchao mntsda3]# mount -o remount /dev/shm
[root@centos-fuwenchao mntsda3]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             9.7G  4.6G  4.7G  50% /
tmpfs                 1.0G  228K  1.0G   1% /dev/shm
/dev/sr0              4.1G  4.1G     0 100% /media/CentOS_6.4_Final
/dev/sda3              38G  176M   36G   1% /mnt/mntsda3

参考:

转载于:https://www.cnblogs.com/diffx/p/11005756.html

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐