You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an application that I'm migrating from gorilla/websocket to nhooyr. Changing the code is straightforward based on the chat example. This is the core send loop:
func (h*SocketHub) subscribe(ctx context.Context, conn*websocket.Conn) error {
ctx=conn.CloseRead(ctx)
s:=&socketSubscriber{
send: make(chan []byte, 1024),
closeSlow: func() {
conn.Close(websocket.StatusPolicyViolation, "connection too slow to keep up with messages")
},
}
h.addSubscriber(s)
deferh.deleteSubscriber(s)
// send welcome messages.send<- []byte(`{"bufferSoc":0,"loadpoints.0.phasesConfigured":null,"savingsTotalCharged":12.804,"loadpoints.0.pvAction":"inactive","auth":{"vehicles":{}},"batteryCapacity":13,"smartCostUnit":"gCO2eq","vehicles":["blauer e-Golf","weißes Model 3","grüner Honda e","schwarzes VanMoof","Wärmepumpe"],"loadpoints.0.phasesActive":1,"loadpoints.0.phaseRemaining":0,"loadpoints.1.chargePower":0,"loadpoints.0.connectedDuration":0,"loadpoints.0.guardAction":"inactive","loadpoints.0.vehicleIcon":"","loadpoints.0.mode":"pv","loadpoints.1.phasesEnabled":0,"loadpoints.0.connected":true,"batteryConfigured":true,"residualPower":0,"loadpoints.0.maxCurrent":16,"sponsor":"sponsorship unavailable","loadpoints.0.phasesEnabled":1,"loadpoints.1.vehicleCapacity":80,"loadpoints.0.enabled":true,"loadpoints.1.phaseRemaining":0,"loadpoints.1.guardAction":"inactive","version":"0.0.1-alpha","sponsorTokenExpires":0,"loadpoints.0.minCurrent":6,"loadpoints.0.vehicleCapacity":44,"loadpoints.1.phasesActive":3,"loadpoints.1.phaseAction":"inactive","loadpoints.1.vehiclePresent":true,"loadpoints.1.vehicleIcon":"","loadpoints.1.mode":"off","savingsEffectivePrice":0.082125,"gridConfigured":true,"loadpoints.0.phaseAction":"inactive","loadpoints.0.vehicleTargetSoc":0,"loadpoints.1.minCurrent":6,"loadpoints.1.targetSoc":75,"loadpoints.1.targetEnergy":0,"loadpoints.0.charging":true,"prioritySoc":0,"loadpoints.0.chargerFeatureIntegratedDevice":false,"loadpoints.0.vehicleDetectionActive":false,"loadpoints.1.guardRemaining":0,"loadpoints.0.chargeCurrent":16,"batterySoc":55,"tariffEffectivePrice":0.08,"loadpoints.0.vehicleSoc":62.2,"pv":[{"power":8179.472084980387}],"loadpoints.0.chargePower":3680,"batteryPower":0,"siteTitle":"Zuhause","savingsSince":"2023-03-09T22:59:09+01:00","loadpoints.0.minSoc":0,"loadpoints.0.vehicleTitle":"blauer e-Golf","loadpoints.0.planActive":false,"gridPower":-4175.3,"homePower":324.22,"tariffCo2":675,"savingsSelfConsumptionCharged":12.626,"loadpoints.0.pvRemaining":0,"loadpoints.0.vehicleRange":182,"loadpoints.1.title":"Garage","loadpoints.1.pvAction":"inactive","loadpoints.1.phasesConfigured":0,"loadpoints.1.chargerFeatureIntegratedDevice":false,"loadpoints.1.chargerIcon":"","battery":[{"power":0,"soc":55,"capacity":13.4}],"loadpoints.0.guardRemaining":0,"loadpoints.0.targetEnergy":0,"loadpoints.0.vehiclePresent":true,"loadpoints.1.maxCurrent":16,"loadpoints.0.chargeRemainingDuration":13296,"loadpoints.0.chargeRemainingEnergy":13591,"greenShare":1,"savingsGridCharged":0.17814,"loadpoints.1.vehicleRange":0,"loadpoints.0.chargedEnergy":0.0014228,"tariffFeedIn":0.08,"tariffEffectiveCo2":0,"smartCostLimit":0,"currency":"EUR","loadpoints.1.minSoc":0,"loadpoints.1.vehicleTitle":"weißes Model 3","savingsSelfConsumptionPercent":98.609,"availableVersion":"0.116.7","loadpoints.0.chargerIcon":"","loadpoints.1.vehicleFeatureOffline":false,"pvPower":8179.5,"loadpoints.0.chargeDuration":0,"loadpoints.1.vehicleTargetSoc":0,"tariffGrid":0.399,"savingsAmount":4.0079,"pvConfigured":true,"loadpoints.0.title":"Carport","loadpoints.0.targetSoc":90,"loadpoints.1.pvRemaining":0,"smartCostAvailable":true,"loadpoints.0.vehicleFeatureOffline":false,"loadpoints.1.vehicleSoc":0,"loadpoints.1.vehicleDetectionActive":false}`)
for {
select {
casemsg:=<-s.send:
iferr:=writeTimeout(ctx, socketWriteTimeout, conn, msg); err!=nil {
returnerr
}
case<-ctx.Done():
returnctx.Err()
}
}
}
The welcome message contains a bunch of JSON state that each client obtains on connection. This works with Chrome and Firefox, but not Safari. On Safari, the client apparently receives the data but then disconnects. Server log sometimes shows
failed to write msg: failed to write: failed to write data frame: WebSocket closed: received close frame: status = StatusProtocolError and reason = ""
The error does not happens when no welcome message is sent or the welcome message is small. I did not try yet to determine if the size of message has a clear bound for the error to occur.
Any idea what might be special about Safari in this context?
The text was updated successfully, but these errors were encountered:
I have an application that I'm migrating from gorilla/websocket to nhooyr. Changing the code is straightforward based on the chat example. This is the core send loop:
The welcome message contains a bunch of JSON state that each client obtains on connection. This works with Chrome and Firefox, but not Safari. On Safari, the client apparently receives the data but then disconnects. Server log sometimes shows
The error does not happens when no welcome message is sent or the welcome message is small. I did not try yet to determine if the size of message has a clear bound for the error to occur.
Any idea what might be special about Safari in this context?
The text was updated successfully, but these errors were encountered: