mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 18:02:25 -05:00 
			
		
		
		
	[bugfix] fix possible mutex lockup during streaming code (#2633)
* rewrite Stream{} to use much less mutex locking, update related code
* use new context for the stream context
* ensure stream gets closed on return of writeTo / readFrom WSConn()
* ensure stream write timeout gets cancelled
* remove embedded context type from Stream{}, reformat log messages for consistency
* use c.Request.Context() for context passed into Stream().Open()
* only return 1 boolean, fix tests to expect multiple stream types in messages
* changes to ping logic
* further improved ping logic
* don't export unused function types, update message sending to only include relevant stream type
* ensure stream gets closed 🤦
* update to error log on failed json marshal (instead of panic)
* inverse websocket read error checking to _ignore_ expected close errors
	
	
This commit is contained in:
		
					parent
					
						
							
								8cafa6b74b
							
						
					
				
			
			
				commit
				
					
						291e180990
					
				
			
		
					 14 changed files with 535 additions and 451 deletions
				
			
		|  | @ -18,20 +18,29 @@ | |||
| package stream | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 
 | ||||
| 	"codeberg.org/gruf/go-byteutil" | ||||
| 	apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" | ||||
| 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" | ||||
| 	"github.com/superseriousbusiness/gotosocial/internal/log" | ||||
| 	"github.com/superseriousbusiness/gotosocial/internal/stream" | ||||
| ) | ||||
| 
 | ||||
| // Notify streams the given notification to any open, appropriate streams belonging to the given account. | ||||
| func (p *Processor) Notify(n *apimodel.Notification, account *gtsmodel.Account) error { | ||||
| 	bytes, err := json.Marshal(n) | ||||
| func (p *Processor) Notify(ctx context.Context, account *gtsmodel.Account, notif *apimodel.Notification) { | ||||
| 	b, err := json.Marshal(notif) | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("error marshalling notification to json: %s", err) | ||||
| 		log.Errorf(ctx, "error marshaling json: %v", err) | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	return p.toAccount(string(bytes), stream.EventTypeNotification, []string{stream.TimelineNotifications, stream.TimelineHome}, account.ID) | ||||
| 	p.streams.Post(ctx, account.ID, stream.Message{ | ||||
| 		Payload: byteutil.B2S(b), | ||||
| 		Event:   stream.EventTypeNotification, | ||||
| 		Stream: []string{ | ||||
| 			stream.TimelineNotifications, | ||||
| 			stream.TimelineHome, | ||||
| 		}, | ||||
| 	}) | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue