junit-team / junit4

A programmer-oriented testing framework for Java.
https://junit.org/junit4
Eclipse Public License 1.0
8.53k stars 3.29k forks source link

OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Time-limited test" #1700

Closed wlnirvana closed 3 years ago

wlnirvana commented 3 years ago

This issue only happens in our production server but can be quite stably reproduced. Even though timeout is set, the tests run extremely slow, with the following error printed out occasionally.

me@server:~/tmp/slow$ time bash run.sh 
JUnit version 4.13.1
.E.E.E.E.E.E.
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Time-limited test"
EException in thread "main" java.lang.OutOfMemoryError: Java heap space

real    2m22.126s
user    2m58.999s
sys     0m1.887s

Project to reproduce the issue: slow.tar.gz

Steps to reproduce the issue: just uncompress the tarball and run bash run.sh

Environment info:

root@server:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:        18.04
Codename:       bionic

root@server:~# uname -a
Linux server 4.15.0-88-generic #88-Ubuntu SMP Tue Feb 11 20:11:34 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

root@server:~# cat /proc/cpuinfo
processor       : 0 
vendor_id       : AuthenticAMD
cpu family      : 23                               
model           : 49
model name      : AMD EPYC 7K62 48-Core Processor
stepping        : 0
microcode       : 0x1000065   
cpu MHz         : 2595.124
cache size      : 512 KB
physical id     : 0                              
siblings        : 2
core id         : 0        
cpu cores       : 2       
apicid          : 0     
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm rep_good nopl cpuid extd_a
picid tsc_known_freq pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy cr8_legacy abm sse4a misalignsse 3dnowprefetch osv
w topoext ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 arat
bugs            : fxsave_leak sysret_ss_attrs spectre_v1 spectre_v2 spec_store_bypass
bogomips        : 5190.24
TLB size        : 1024 4K pages                                                                                                                                                               clflush size    : 64                                                                                                                                                                          cache_alignment : 64                                                                                              
address sizes   : 48 bits physical, 48 bits virtual                                  
power management:        

processor       : 1 
vendor_id       : AuthenticAMD
cpu family      : 23                               
model           : 49
model name      : AMD EPYC 7K62 48-Core Processor
stepping        : 0
microcode       : 0x1000065
cpu MHz         : 2595.124
cache size      : 512 KB
physical id     : 0
siblings        : 2
core id         : 1
cpu cores       : 2
apicid          : 1
initial apicid  : 1
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm rep_good nopl cpuid extd_apicid tsc_known_freq pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw topoext ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 arat
bugs            : fxsave_leak sysret_ss_attrs spectre_v1 spectre_v2 spec_store_bypass
bogomips        : 5190.24
TLB size        : 1024 4K pages
clflush size    : 64
cache_alignment : 64
address sizes   : 48 bits physical, 48 bits virtual
power management:
marcphilipp commented 3 years ago

This is not an issue of JUnit but your application under test. I recommend running tests with -XX:+HeapDumpOnOutOfMemoryError to see if you might have a memory leak or just need to give your test JVM more memory.