How to fix Session Not Created Exception in Jenkins?

The below error is displayed at the Jenkins console.

**org.openqa.selenium.SessionNotCreatedException: **
**Could not start a new session. Response code 500. Message: Process unexpectedly closed with status 1 **
Host info: host: ‘ip-10-1-1-111’, ip: ‘10.1.1.111’
Build info: version: ‘4.7.2’, revision: ‘4d4020c3b7’
System info: os.name: ‘Linux’, os.arch: ‘amd64’, os.version: ‘5.19.0-1025-aws’, java.version: ‘11.0.20.1’
Driver info: org.openqa.selenium.firefox.FirefoxDriver

I have executed the automation code on my local machine (windows 11, JDK 11) successfully.
below is the web driver declared in my base class.

WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();

When I pushed the code into my Git repository Jenkins job got triggered where all the plugins got installed but the build failed due to the above-mentioned error.

How to run my automation test cases on the Jenkins server?

The console output is:
Started by GitHub push by Jeyasankar94
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/QaVisionias
The recommended git tool is: NONE
No credentials specified

git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/QaVisionias/.git # timeout=10
Fetching changes from the remote Git repository
git config remote.origin.url https://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@github.com/visionitlabs/visionweb_qa.git # timeout=10
Fetching upstream changes from https://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@github.com/visionitlabs/visionweb_qa.git
git --version # timeout=10
git --version # ‘git version 2.34.1’
git fetch --tags --force --progress – https://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@github.com/visionitlabs/visionweb_qa.git +refs/heads/:refs/remotes/origin/ # timeout=10
git rev-parse refs/remotes/origin/dev^{commit} # timeout=10
Checking out Revision 2f09a4eab25c5839ed17bcca13eca4fe5ff6d098 (refs/remotes/origin/dev)
git config core.sparsecheckout # timeout=10
git checkout -f 2f09a4eab25c5839ed17bcca13eca4fe5ff6d098 # timeout=10
Commit message: “Jenkins build”
git rev-list --no-walk 75d3c5dc43c5d83b6bb5e58021b78380d7576b7d # timeout=10
No emails were triggered.
[QaVisionias] $ /bin/sh -xe /tmp/jenkins157966229410011120.sh

    • Xvfb :10 -ac
      export DISPLAY=:10
      (EE)
      Fatal server error:
      (EE) Server is already active for display 10
      If this server is no longer running, remove /tmp/.X10-lock
      and start again.
      (EE)
      [QaVisionias] $ /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven3/bin/mvn -f pom.xml clean install
      [INFO] Scanning for projects…
      [WARNING]
      [WARNING] Some problems were encountered while building the effective model for VISIONIAS:QaVisionias:jar:0.0.1-SNAPSHOT
      [WARNING] ‘dependencies.dependency.(groupId:artifactId:type:classifier)’ must be unique: com.fasterxml.jackson.core:jackson-databind:jar → duplicate declaration of version 2.13.1 @ line 82, column 15
      [WARNING] ‘dependencies.dependency.(groupId:artifactId:type:classifier)’ must be unique: commons-io:commons-io:jar → duplicate declaration of version 2.11.0 @ line 87, column 15
      [WARNING] ‘dependencies.dependency.(groupId:artifactId:type:classifier)’ must be unique: org.apache.poi:poi:jar → duplicate declaration of version 5.2.3 @ line 92, column 15
      [WARNING] ‘dependencies.dependency.(groupId:artifactId:type:classifier)’ must be unique: org.apache.poi:poi-ooxml:jar → duplicate declaration of version 5.2.3 @ line 97, column 15
      [WARNING] ‘dependencies.dependency.(groupId:artifactId:type:classifier)’ must be unique: com.googlecode.json-simple:json-simple:jar → duplicate declaration of version 1.1.1 @ line 107, column 15
      [WARNING] ‘dependencies.dependency.(groupId:artifactId:type:classifier)’ must be unique: io.github.bonigarcia:webdrivermanager:jar → duplicate declaration of version 5.3.1 @ line 112, column 15
      [WARNING] ‘dependencies.dependency.(groupId:artifactId:type:classifier)’ must be unique: com.fasterxml.jackson.core:jackson-databind:jar → duplicate declaration of version 2.13.1 @ line 117, column 15
      [WARNING]
      [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
      [WARNING]
      [WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
      [WARNING]
      [INFO]
      [INFO] -----------------------< VISIONIAS:QaVisionias >------------------------
      [INFO] Building QaVisionias 0.0.1-SNAPSHOT
      [INFO] from pom.xml
      [INFO] --------------------------------[ jar ]---------------------------------
      [INFO]
      [INFO] — clean:3.2.0:clean (default-clean) @ QaVisionias —
      [INFO] Deleting /var/lib/jenkins/workspace/QaVisionias/target
      [INFO]
      [INFO] — resources:3.3.1:resources (default-resources) @ QaVisionias —
      [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
      [INFO] Copying 1 resource from src/main/resources to target/classes
      [INFO]
      [INFO] — compiler:3.10.1:compile (default-compile) @ QaVisionias —
      [INFO] No sources to compile
      [INFO]
      [INFO] — resources:3.3.1:testResources (default-testResources) @ QaVisionias —
      [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
      [INFO] Copying 1 resource from src/test/resources to target/test-classes
      [INFO]
      [INFO] — compiler:3.10.1:testCompile (default-testCompile) @ QaVisionias —
      [INFO] Changes detected - recompiling the module!
      [WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
      [INFO] Compiling 53 source files to /var/lib/jenkins/workspace/QaVisionias/target/test-classes
      [INFO] /var/lib/jenkins/workspace/QaVisionias/src/test/java/org/basepackage/VisionBaseClass.java: Some input files use or override a deprecated API.
      [INFO] /var/lib/jenkins/workspace/QaVisionias/src/test/java/org/basepackage/VisionBaseClass.java: Recompile with -Xlint:deprecation for details.
      [INFO]
      [INFO] — surefire:3.1.2:test (default-test) @ QaVisionias —
      [INFO] Using auto detected provider org.apache.maven.surefire.testng.TestNGProvider
      [INFO]
      [INFO] -------------------------------------------------------
      [INFO] T E S T S
      [INFO] -------------------------------------------------------
      [INFO] Running TestSuite
      SLF4J: No SLF4J providers were found.
      SLF4J: Defaulting to no-operation (NOP) logger implementation
      SLF4J: See SLF4J Error Codes for further details.
      1695196002568 geckodriver INFO Listening on 127.0.0.1:26629
      /system.slice/jenkins.service is not a snap cgroup
      1695196002990 mozrunner::runner INFO Running command: MOZ_CRASHREPORTER=“1” MOZ_CRASHREPORTER_NO_REPORT=“1” MOZ_CRASHREPORTER_SHUTDOWN=“1” MOZ_NO_REMOTE=“1” “/usr … s” “http://127.0.0.1:11196/,http://localhost:11196/,http://[::1]:11196/” “-no-remote” “-profile” “/tmp/rust_mozprofileDFaDqa”
      /system.slice/jenkins.service is not a snap cgroup
      [ERROR] Tests run: 3, Failures: 1, Errors: 0, Skipped: 2, Time elapsed: 4.917 s <<< FAILURE! – in TestSuite
      [ERROR] org.testpackage.TC001_Signup.launchorg.testng.TestRunner@10272bbb, firefox – Time elapsed: 4.365 s <<< FAILURE!
      org.openqa.selenium.SessionNotCreatedException:
      Could not start a new session. Response code 500. Message: Process unexpectedly closed with status 1
      Host info: host: ‘ip-10-1-1-111’, ip: ‘10.1.1.111’
      Build info: version: ‘4.7.2’, revision: ‘4d4020c3b7’
      System info: os.name: ‘Linux’, os.arch: ‘amd64’, os.version: ‘5.19.0-1025-aws’, java.version: ‘11.0.20.1’
      Driver info: org.openqa.selenium.firefox.FirefoxDriver
      Command: [null, newSession {capabilities=[Capabilities {acceptInsecureCerts: true, browserName: firefox, moz:debuggerAddress: true, moz:firefoxOptions: {}}], desiredCapabilities=Capabilities {acceptInsecureCerts: true, browserName: firefox, moz:debuggerAddress: true, moz:firefoxOptions: {}}}]
      at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:148)
      at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:106)
      at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
      at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
      at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
      at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
      at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:535)
      at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:228)
      at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:156)
      at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:130)
      at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:111)
      at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:101)
      at org.basepackage.VisionBaseClass.launch(VisionBaseClass.java:145)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
      at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
      at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:385)
      at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:321)
      at org.testng.internal.TestInvoker.runConfigMethods(TestInvoker.java:700)
      at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:527)
      at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
      at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
      at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824)
      at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
      at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
      at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
      at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
      at org.testng.TestRunner.privateRun(TestRunner.java:794)
      at org.testng.TestRunner.run(TestRunner.java:596)
      at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
      at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
      at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
      at org.testng.SuiteRunner.run(SuiteRunner.java:276)
      at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
      at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
      at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
      at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
      at org.testng.TestNG.runSuites(TestNG.java:1063)
      at org.testng.TestNG.run(TestNG.java:1031)
      at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:308)
      at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:71)
      at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:113)
      at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
      at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
      at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
      at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)

[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] TC001_Signup>VisionBaseClass.launch:145 » SessionNotCreated Could not start a new session. Response code 500. Message: Process unexpectedly closed with status 1

Connection error sending email, retrying once more in 10 seconds…
Connection error sending email, retrying once more in 10 seconds…
Failed after second try sending email
Finished: FAILURE

Jenkins setup:
Jenkins: 2.387.3
OS: Linux - 5.19.0-1025-aws
Java: 11.0.20.1 - Ubuntu (OpenJDK 64-Bit Server VM)

ant:487.vd79d090d4ea_e
antisamy-markup-formatter:159.v25b_c67cd35fb_
apache-httpcomponents-client-4-api:4.5.14-150.v7a_b_9d17134a_5
bootstrap5-api:5.3.0-1
bouncycastle-api:2.28
branch-api:2.1092.vda_3c2a_a_f0c11
build-timeout:1.30
caffeine-api:3.1.8-133.v17b_1ff2e0599
checks-api:2.0.0
cloudbees-folder:6.815.v0dd5a_cb_40e0e
commons-lang3-api:3.12.0-36.vd97de6465d5b_
commons-text-api:1.10.0-36.vc008c8fcda_7b_
credentials:1254.vb_96f366e7b_a_d
credentials-binding:604.vb_64480b_c56ca_
display-url-api:2.3.7
durable-task:507.v050055d0cb_dd
echarts-api:5.4.0-4
email-ext:2.97
font-awesome-api:6.3.0-2
git:5.0.2
git-client:4.2.0
github:1.37.1
github-api:1.314-431.v78d72a_3fe4c3
github-branch-source:1703.vd5a_2b_29c6cdc
gradle:2.7
htmlpublisher:1.32
instance-identity:142.v04572ca_5b_265
ionicons-api:56.v1b_1c8c49374e
jackson2-api:2.15.1-344.v6eb_55303dc3e
jakarta-activation-api:2.0.1-3
jakarta-mail-api:2.0.1-3
javadoc:243.vb_b_503b_b_45537
javax-activation-api:1.2.0-6
javax-mail-api:1.6.2-9
jaxb:2.3.8-1
jjwt-api:0.11.5-77.v646c772fddb_0
jquery3-api:3.7.0-1
jsch:0.2.8-65.v052c39de79b_2
junit:1217.v4297208a_a_b_ce
ldap:682.v7b_544c9d1512
mailer:463.vedf8358e006b_
matrix-auth:3.1.7
matrix-project:789.v57a_725b_63c79
maven-plugin:3.23
mina-sshd-api-common:2.10.0-69.v28e3e36d18eb_
mina-sshd-api-core:2.10.0-69.v28e3e36d18eb_
okhttp-api:4.10.0-132.v7a_7b_91cef39c
pam-auth:1.10
pipeline-build-step:491.v1fec530da_858
pipeline-github-lib:42.v0739460cda_c4
pipeline-graph-analysis:202.va_d268e64deb_3
pipeline-groovy-lib:656.va_a_ceeb_6ffb_f7
pipeline-input-step:468.va_5db_051498a_4
pipeline-milestone-step:111.v449306f708b_7
pipeline-model-api:2.2131.vb_9788088fdb_5
pipeline-model-definition:2.2131.vb_9788088fdb_5
pipeline-model-extensions:2.2131.vb_9788088fdb_5
pipeline-rest-api:2.32
pipeline-stage-step:305.ve96d0205c1c6
pipeline-stage-tags-metadata:2.2131.vb_9788088fdb_5
pipeline-stage-view:2.32
plain-credentials:143.v1b_df8b_d3b_e48
plugin-util-api:3.2.1
resource-disposer:0.22
scm-api:672.v64378a_b_20c60
script-security:1275.v23895f409fb_d
slack:664.vc9a_90f8b_c24a_
snakeyaml-api:1.33-95.va_b_a_e3e47b_fa_4
ssh-credentials:305.v8f4381501156
ssh-slaves:2.877.v365f5eb_a_b_eec
sshd:3.303.vefc7119b_ec23
structs:324.va_f5d6774f3a_d
timestamper:1.25
token-macro:359.vb_cde11682e0c
trilead-api:2.84.v72119de229b_7
variant:59.vf075fe829ccb
workflow-aggregator:596.v8c21c963d92d
workflow-api:1213.v646def1087f9
workflow-basic-steps:1017.vb_45b_302f0cea_
workflow-cps:3659.v582dc37621d8
workflow-durable-task-step:1246.v5524618ea_097
workflow-job:1295.v395eb_7400005
workflow-multibranch:746.v05814d19c001
workflow-scm-step:408.v7d5b_135a_b_d49
workflow-step-api:639.v6eca_cd8c04a_a_
workflow-support:839.v35e2736cfd5c
ws-cleanup:0.45

I see this error in your log:

export DISPLAY=:10 (EE) Fatal server error: (EE) Server is already active for display 10 If this server is no longer running, remove /tmp/.X10-lock and start again.

Seems like something already has a session open on :10 which could cause the session to not start for Selenium I believe.

That error is because of Xvfb :10 -ac &

I was running in build step. I have removed it and that error isn’t coming. Still session not able to start

It says Running as SYSTEM does the system user have access to the display? If you are starting the display as another user, you may need to allow access to the session for all users.