brendonmatos/golive

page reloads unmounts old components but they are destroyed in the server and still try push data

Closed this issue · 4 comments

step to reproduce:

  • run server with 1 or more components (like clock one which updates via server events)
  • reload the page
  • see the warning WRN handle ws request: unexpected connection close
  • start seeing errors every timestep the clock old clock component was updating

Error logs below

 ┌───────────────────────────────────────────────────┐ 
 │                    Fiber v2.2.3                   │ 
 │               http://127.0.0.1:9000               │ 
 │                                                   │ 
 │ Handlers ............. 4  Processes ........... 1 │ 
 │ Prefork ....... Disabled  PID ........... 2042802 │ 
 └───────────────────────────────────────────────────┘ 

GL 16:10:42 WRN handle ws request: unexpected connection close
GL 16:10:42 ERR call to commit on unmounted Component name=Root_bHk6G
GL 16:10:42 ERR call to commit on unmounted Component name=Root_ksoMy
GL 16:10:43 ERR call to commit on unmounted Component name=Root_bHk6G
GL 16:10:43 ERR call to commit on unmounted Component name=Root_ksoMy
GL 16:10:44 ERR call to commit on unmounted Component name=Root_bHk6G
GL 16:10:44 ERR call to commit on unmounted Component name=Root_ksoMy
GL 16:10:45 ERR call to commit on unmounted Component name=Root_ksoMy
GL 16:10:45 ERR call to commit on unmounted Component name=Root_bHk6G
GL 16:10:46 ERR call to commit on unmounted Component name=Root_bHk6G
GL 16:10:46 ERR call to commit on unmounted Component name=Root_ksoMy
GL 16:10:47 ERR call to commit on unmounted Component name=Root_bHk6G
GL 16:10:47 ERR call to commit on unmounted Component name=Root_ksoMy
GL 16:10:48 ERR call to commit on unmounted Component name=Root_ksoMy
GL 16:10:48 ERR call to commit on unmounted Component name=Root_bHk6G
GL 16:10:49 WRN handle ws request: unexpected connection close
GL 16:10:49 ERR call to commit on unmounted Component name=Root_gf946
GL 16:10:49 ERR call to commit on unmounted Component name=Root_i4d5f
GL 16:10:49 ERR call to commit on unmounted Component name=Root_bHk6G
GL 16:10:49 ERR call to commit on unmounted Component name=Root_ksoMy
GL 16:10:50 ERR call to commit on unmounted Component name=Root_i4d5f
GL 16:10:50 ERR call to commit on unmounted Component name=Root_gf946
GL 16:10:50 ERR call to commit on unmounted Component name=Root_bHk6G
GL 16:10:50 ERR call to commit on unmounted Component name=Root_ksoMy
GL 16:10:51 ERR call to commit on unmounted Component name=Root_i4d5f
GL 16:10:51 ERR call to commit on unmounted Component name=Root_gf946
GL 16:10:51 ERR call to commit on unmounted Component name=Root_ksoMy
GL 16:10:51 ERR call to commit on unmounted Component name=Root_bHk6G
GL 16:10:52 ERR call to commit on unmounted Component name=Root_gf946
GL 16:10:52 ERR call to commit on unmounted Component name=Root_i4d5f

I dont know much about the codebase and architecture yet but I can try to fix it and create PR

This is certainly a bug. In components with asynchronous behavior they must contain a check for whether the component is in the exited state

func (c *Clock) Mounted(l *golive.LiveComponent) {
	go func() {
		for {
			if l.Exited {
				return
			}
			c.ActualTime = formattedActualTime()
			time.Sleep(time.Second)
			c.Commit()
		}
	}()
}

This is the code part responsible for killing components along with children:

if err := session.LivePage.entryComponent.Kill(); err != nil {

thanks @brendonmatos will see if i can help make it easy with a fix