Epic memory leak detected while scrolling through long directories.  ForkWrapper::connect_parent_fd() allocates sockets which are never closed.  The close function is being called properly but the kernal isn't releasing the sockets anyway.  It endlessly increments the socket number until 1023.  netstat shows a growing number of TIMED_WAIT sockets still open.  They all go away after the crash but not until the crash.

 This might have been affecting all file reads, hence loading many long playlists could crash it.

 The mane program forks into a subprocess which waits for a connection from the mane program.  To close the file, the subprocess closes its listening socket while the mane program's socket is still open, which might cause it to get into TIMED_WAIT.

 Attempt 1: wait for a socket read to fail on the subprocess side.  Read just locked up after the socket was closed, indicating someone else still owned it.

 Attempt 2: use a temp_pipe to signal the closure of the mane program side.  It still didn't close the parent_fd.

 This bug was introduced by the migration away from libancillary.  That ended up being another dud library.

 Upon further review, all the files are opened through the MWindow::file_server so the subprocesses are all parented by the mane program.

Noted it only happens when the file contains video & the file previewer renders the video.  Audio doesn't leak.  Verified the files are all being closed.  The playback engine closes the previous file when it opens the next file.

Successive disabling of random functions narrowed it down to PlaybackEngine::arm_render_engine -> RenderEngine::create_render_threads -> VRender constructor

When inspecting the VRender constructor, noted it was allocating timer & never deleting it.  Deleting timer fixed the socket leak.  The Timer class creates a dummy file descriptor which allows a delay to be interrupted.  This was what allowed very slow framerates to be interrupted between frames.  The FileFork was not the source of the leak.

TIME_WAIT 

It still creates loads of TIME_WAIT sockets, but it's not leaking file descriptors.  It would be nice to get rid of those TIME_WAIT sockets.  They stay around for a few minutes after quitting the program.  For the 1st time in 30 years, lions came agutser for not using ntohs to print the port numbers.  Netstat ports which didn't match ForkWrapper finally did, narrowing it down to the parent_fd, child_fd.

 While lions were previously able to prevent TIME_WAIT in some server programs, the current gemini answer says they're unavoidable.  The only way out is to use connection pooling. Instead of every ForkWrapper child process creating a new socket & listening for a connection from the parent, the parents would reuse a pool of sockets to listen & the childs would connect.  

The problem is it seems to require the listener to be the child process.  It has to create all the child processes as dummies under a single parent process.  Then it passes the port numbers from the dummies to the true parent processes where the real connection is made.

Since FileServer creates only 1 FileFork at a time, FileServer could own a single parent_fd which all the FileFork childs connect to.

All the ForkWrappers created as a dummy_fork would skip creating their own parent_fd.  MWindow::init_fileserver starts FileServer/ForkWrapper with is_dummy=0 so it would know to create the single parent_fd.  The trick is having the new dummy_fork call listen() on FileServer's parent_fd before creating the subprocess.  Its start() call would take in FileServer's parent_fd.  Then its setup_dummy() has to call accept() on the FileServer parent_fd.

Helas, this still left many TIME_WAIT but only consumed half the number of ports.  They all shared the same parent_fd.  It also was a lot simpler to synchronize the connections.  The memory management is complex.

Mane program: FileServer/ForkWrapper + FileFork/ForkWrapper dummy parent + address of real parent in FileServer subprocess

FileServer subprocess:  FileFork/ForkWrapper real parent + pid of real child

FileFork Subprocess: FileFork/ForkWrapper real child

  It has to delete the dummy FileFork in the mane program, the real parent in the FileServer subprocess & the real child in the FileFork subprocess.  The real parent also has to rejoin with the pid of the real child but the dummy FileFork in the mane program doesn't have to rejoin with anything.  The mane program doesn't have the pid of the FileFork subprocess.

The mane program address is always a 6 byte 0x7f address.  The FileServer subprocess address is always 4 bytes.   

 

--------------------------------------------------------------------------------

Some interesting payoffs finally starting to appear from AI agent tools.

 https://www.quakecstudio.com/

A quake C IDE, entirely vibe coded.  Lions barely remember quake C but more clearly remember the BSP compiler.  It only ran in Windows & took forever.  Helas, the modern creation probably replayed 30 years of past source code.

 https://github.com/alesha-pro/llm.asm/tree/main/02-baremetal-os

A bare metal framework for running language models without an OS.  More importantly, AI agents allowed it to be pure assembly.  Helas, you're more likely going to run the language models on a GPU.  In this case, it replayed previous higher level code & compiled it.

Nothing lions will ever use, but these are new projects with a practical use somewhere.  Previously, we saw useless features added to existing projects or useless hat tricks.  They're all still replays of prior work, by animals who probably needed less experience than doing it manually.

---------------------------------------------------------------------------------

Moving on, 8 bit guy's next AI creation came out.

 


Good idea: heroine proposing to man 


Bad idea: a traditional grandma response to proposing in an airport
 


Then the niagra falls of tears from the ex girlfriend when the plane disappears.  These 2 scenes made lions wonder if humans are going to become as out of place & dysfunctional as the characters in their AI generated movies, the same way they now talk like language models.  Are they going to start getting married in airports?

Noted it still costs money to create any amount of full motion video at all. 

 ------------------------------------------------------------------

 


A year after the failed Iranian revolution & failed war, the world has manely figured out how to survive without the straight of Hormuz.  New pipelines have been built.  1 thing lions always wonder is how so many Iranian military leaders are still alive unless US did absolutely nothing or they're faking it.  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Comments

Popular posts from this blog