jart / cosmopolitan

build-once run-anywhere c library
ISC License
17.37k stars 597 forks source link

redbean_test.com ECONNRESET error #208

Open ahgamut opened 3 years ago

ahgamut commented 3 years ago

@jart same screenshot from #207:

2021-07-06_00-36-58_1366x768

Steps I followed:

  1. git clone https://github.com/jart/cosmopolitan && cd cosmopolitan
  2. make -j4
  3. see above error on screen

I'm running the make process on a tmpfs if that's relevant, but even copying redbean_test.com.dbg to a regular directory produces the same error. Is it related to my system (Debian 10 Buster, Linux 4.19.0-12-amd64) specifically?

jart commented 3 years ago

Can you cat /proc/cpuinfo?

ahgamut commented 3 years ago
processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 69
model name  : Intel(R) Core(TM) i5-4200U CPU @ 1.60GHz
stepping    : 1
microcode   : 0x26
cpu MHz     : 941.627
cache size  : 3072 KB
physical id : 0
siblings    : 4
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 dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d
bugs        : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds
bogomips    : 4589.34
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

<same as above>
ahgamut commented 2 years ago

@jart so this was still happening with every build I tried up until 933f33bcc1b1664cc065a668f35c3d349779247a, but the error/fix is not related to cpuinfo.

Screenshot of error log:

2022-04-17_04-44-13_1366x768

Error log shows write key (grep -0x006c).

-0x006C is the errno corresponding to MBEDTLS_ERR_ASN1_BUF_TOO_SMALL The error is triggered at net/https/finishcertificate.c when calling the function mbedtls_x509write_crt_der. The buffer provided to that function holds 65536 bytes. I checked that the memory allocation was valid, so the error was indeed due to 65536 bytes not being enough.

I copied the FATALF call in FinishCertificate into the MBEDTLS_ASN1_CHK_ADD macro and found that the error happens within mbedtls_x509_write_extensions, which has a while(x != NULL) loop that appends to the buffer.

I was testing the code around the function call(s) shown in the backtrace, to no avail. But then I did something unrelated: I reset /etc/hosts to its default, and the error went away!

So the steps to replicate this error:

What does mbedtls_x509_write_extensions have to do with /etc/hosts? I am not sure. I changed the while(x != NULL) loop to terminate after 4 entries, and redbean_test.com passes.

CalebJohn commented 2 years ago

Just to add another data point to this, I've run into the same error with the latest demo (redbean-demo-2.0.8.com). I can also trace the problem to my /etc/hosts file, which uses the someonewhocares hosts. Replacing /etc/hosts with the default, or truncating the file to <49,000 bytes fixes the error. Additionally run with the -X flag also allows redbean to run fine.

Here is the error I see when running the demo

$ ./redbean-demo-2.0.8.com
I2022-07-02T22:22:49.115238:tool/net/redbean.c:6952:redbean-demo-2:30525] (srvr) listen http://127.0.0.1:8080
I2022-07-02T22:22:49+000021:tool/net/redbean.c:6952:redbean-demo-2:30525] (srvr) listen http://192.168.1.66:8080
I2022-07-02T22:22:49+000011:tool/net/redbean.c:6952:redbean-demo-2:30525] (srvr) listen http://172.19.0.1:8080
I2022-07-02T22:22:49+000009:tool/net/redbean.c:6952:redbean-demo-2:30525] (srvr) listen http://172.18.0.1:8080
I2022-07-02T22:22:49+000009:tool/net/redbean.c:6952:redbean-demo-2:30525] (srvr) listen http://172.17.0.1:8080
F2022-07-02T22:22:49+013920:net/https/finishcertificate.c:31:redbean-demo-2:30525] write key (grep -0x006c)
error:net/https/finishcertificate.c:31:redbean-demo-2.0.8.com: fatality johnson pid 30525
70000003fc70 000000535729 vflogf+703
70000003fd50 000000535234 flogf+116
70000003fe30 0000004e9b6e FinishCertificate+305
70000003fe80 00000041d6e0 GenerateEcpCertificate+136
70000003ff10 00000041daf8 LoadCertificates+383
70000003ff70 00000041ded2 TlsInit+502
70000003ff90 00000042a010 RedBean+322
70000003ffc0 00000042a503 main+45
70000003ffe0 000000402b3d cosmo+71
7ffd8f8691f0 0000004023f6 _start+116
`cat /proc/cpuinfo`
processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 142
model name  : Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
stepping    : 11
microcode   : 0xea
cpu MHz     : 1800.000
cache size  : 6144 KB
physical id : 0
siblings    : 8
core id     : 0
cpu cores   : 4
apicid      : 0
initial apicid  : 0
fpu     : yes
fpu_exception   : yes
cpuid level : 22
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust sgx bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_capabilities
vmx flags   : vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple pml ept_mode_based_exec
bugs        : spectre_v1 spectre_v2 spec_store_bypass mds swapgs itlb_multihit srbds
bogomips    : 3600.00
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management: