mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 23:33:12 +09:00
Warn on subscription updates with same timestamp
If the value in a subscribed list is updated while the updatedAtMs timestamp is kept the same then the caching logic of the subscription system will cause updates to be silently dropped. Log a warning if a subscriber catches this happening to help tracking down such cases.
This commit is contained in:
1 parent
021af793fc
commit
2e25831b4d
1 file changed
+9
@@ -2,6 +2,7 @@ import { Type, Static } from "@sinclair/typebox";
|
|||||||
import { Link, Event, EventClass, RequestHandler, WebSocketClientConnector, WebSocketBaseConnector } from "./link";
|
import { Link, Event, EventClass, RequestHandler, WebSocketClientConnector, WebSocketBaseConnector } from "./link";
|
||||||
import { logger } from "./logging";
|
import { logger } from "./logging";
|
||||||
import { Address, MessageRequest, IControllerUser } from "./data";
|
import { Address, MessageRequest, IControllerUser } from "./data";
|
||||||
|
import isDeepStrictEqual from "./is_deep_strict_equal";
|
||||||
|
|
||||||
export type SubscriptionRequestHandler<T> = RequestHandler<SubscriptionRequest, Event<T> | null>;
|
export type SubscriptionRequestHandler<T> = RequestHandler<SubscriptionRequest, Event<T> | null>;
|
||||||
export type EventSubscriberCallback<T> = (updates: T[], synced: boolean) => void
|
export type EventSubscriberCallback<T> = (updates: T[], synced: boolean) => void
|
||||||
@@ -204,6 +205,14 @@ export class EventSubscriber<
|
|||||||
async _handle(event: EventSubscribable<T, V>) {
|
async _handle(event: EventSubscribable<T, V>) {
|
||||||
for (const value of event.updates) {
|
for (const value of event.updates) {
|
||||||
this.lastResponseTimeMs = Math.max(this.lastResponseTimeMs, value.updatedAtMs);
|
this.lastResponseTimeMs = Math.max(this.lastResponseTimeMs, value.updatedAtMs);
|
||||||
|
// Warn about updates which changes content but don't update updatedAtMs
|
||||||
|
const existing = this.values.get(value.id as K);
|
||||||
|
if (existing && existing.updatedAtMs === value.updatedAtMs && !isDeepStrictEqual(existing, value)) {
|
||||||
|
logger.warn(
|
||||||
|
`${this.Event.name} contains update for value with id ${value.id} that has an identical ` +
|
||||||
|
"updatedAtMs timestamp but differing content"
|
||||||
|
);
|
||||||
|
}
|
||||||
if (value.isDeleted) {
|
if (value.isDeleted) {
|
||||||
this.values.delete(value.id as K);
|
this.values.delete(value.id as K);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in new issue
Block a user