mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 05:02:25 -05:00 
			
		
		
		
	[bugfix] return early in websocket upgrade handler (#1315)
* launch websocket streaming in goroutine to allow upgrade handler to return * don't send any message on ping, improved close check on failed read * use context to signal wsconn close, ensure canceled in read goroutine Signed-off-by: kim <grufwub@gmail.com>
This commit is contained in:
		
					parent
					
						
							
								98edd75f1b
							
						
					
				
			
			
				commit
				
					
						1bda6a2002
					
				
			
		
					 4 changed files with 110 additions and 70 deletions
				
			
		|  | @ -23,6 +23,7 @@ import ( | |||
| 	"time" | ||||
| 
 | ||||
| 	"github.com/gin-gonic/gin" | ||||
| 	"github.com/gorilla/websocket" | ||||
| 	"github.com/superseriousbusiness/gotosocial/internal/processing" | ||||
| ) | ||||
| 
 | ||||
|  | @ -41,21 +42,22 @@ const ( | |||
| ) | ||||
| 
 | ||||
| type Module struct { | ||||
| 	processor    processing.Processor | ||||
| 	tickDuration time.Duration | ||||
| 	processor processing.Processor | ||||
| 	dTicker   time.Duration | ||||
| 	wsUpgrade websocket.Upgrader | ||||
| } | ||||
| 
 | ||||
| func New(processor processing.Processor) *Module { | ||||
| func New(processor processing.Processor, dTicker time.Duration, wsBuf int) *Module { | ||||
| 	return &Module{ | ||||
| 		processor:    processor, | ||||
| 		tickDuration: 30 * time.Second, | ||||
| 	} | ||||
| } | ||||
| 		processor: processor, | ||||
| 		dTicker:   dTicker, | ||||
| 		wsUpgrade: websocket.Upgrader{ | ||||
| 			ReadBufferSize:  wsBuf, // we don't expect reads | ||||
| 			WriteBufferSize: wsBuf, | ||||
| 
 | ||||
| func NewWithTickDuration(processor processing.Processor, tickDuration time.Duration) *Module { | ||||
| 	return &Module{ | ||||
| 		processor:    processor, | ||||
| 		tickDuration: tickDuration, | ||||
| 			// we expect cors requests (via eg., pinafore.social) so be lenient | ||||
| 			CheckOrigin: func(r *http.Request) bool { return true }, | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue