Comments (6)
I ran into this issue as well. I believe it was because in the default implementation of the y-websocket server, sometimes the sync events are fired before the document is loaded from leveldb
.
In particular, on this line: https://github.com/yjs/y-websocket/blob/master/bin/utils.js#L37 ldb.getYDoc
returns a promise, but getYDoc
in utils.js
does not wait for this promise to resolve before returning the document, which causes sync step 1 to be sent before the document is loaded from leveldb (an empty document is used instead). Then, sync step 2 is sent, leading the client to believe the document is synced (even though the document is still empty). Finally, leveldb is loaded, and the document is updated on the server and synced with the client.
I fixed this by modifying getYDoc
in utils.js
to return both the document and a promise for when leveldb finishes loading the document, and the server will wait until the document is loaded before processing messages (a hacky implementation of this can be found here: cpinitiative/ide@d4380ce and a bugfix here: cpinitiative/ide@48b4240)
from y-websocket.
I met the same problem when yjs server load doc history data from MySQL Database.
It's look like client request history data failed, but the websocket connect server successfully.
I suspect the server-side authentication caused this error, in my case: the yjs server call another auth server and wait for result.
How to fix:
- workaround way
useresyncInterval
option for sync interval to server
more explain: https://github.com/yjs/y-websocket/blob/master/src/y-websocket.js#L248
and resyncInterval default is -1, that means,never resync!
export const provider = new WebsocketProvider(
requestURL,
roomName,
doc,
{
connect: true,
resyncInterval: 1000,
disableBc: true
}
);
- server side need to cache client msg to a queue, when auth done, handle the cache msg
from y-websocket.
Hi @Flamenco,
The "synced" event is fired when the client received the initial state from the server. However, it seems that the server loads the content from leveldb after the client is already synced. This is most likely a bug in the y-leveldb integration.
from y-websocket.
@dmonad OK I will look under the hood in the leveldb code. I'm closing this for now.
from y-websocket.
y-websocket has this code:
websocket.onopen = () => {
provider.wsLastMessageReceived = time.getUnixTime()
provider.wsconnecting = false
provider.wsconnected = true
provider.wsUnsuccessfulReconnects = 0
provider.emit('status', [{
status: 'connected'
}])
// always send sync step 1 when connected
const encoder = encoding.createEncoder()
encoding.writeVarUint(encoder, messageSync)
syncProtocol.writeSyncStep1(encoder, provider.doc)
websocket.send(encoding.toUint8Array(encoder))
// broadcast local awareness state
if (provider.awareness.getLocalState() !== null) {
const encoderAwarenessState = encoding.createEncoder()
encoding.writeVarUint(encoderAwarenessState, messageAwareness)
encoding.writeVarUint8Array(encoderAwarenessState, awarenessProtocol.encodeAwarenessUpdate(provider.awareness, [provider.doc.clientID]))
websocket.send(encoding.toUint8Array(encoderAwarenessState))
}
}
So it appears as you mentioned, sync is sent before any documents are actually loaded from persistence.
from y-websocket.
I've encountered the same issue, where occasionally the ProseMirror document initially renders with blank content (having the corresponding schema's type),
- firstTime with blank content:
![图片](https://private-user-images.githubusercontent.com/41875799/283995881-d7453710-e296-49f5-a207-a9396e10690d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM5NDcyNTUsIm5iZiI6MTcyMzk0Njk1NSwicGF0aCI6Ii80MTg3NTc5OS8yODM5OTU4ODEtZDc0NTM3MTAtZTI5Ni00OWY1LWEyMDctYTkzOTZlMTA2OTBkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE4VDAyMDkxNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTYyYTgxM2FhZTFiZTNlNDZmMDE0ZjJhN2YwOGMxMTRlNjY5Yjk3ODQ3OTIzMjM3ODAzNTdkNGQxYzU1NGI5N2QmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Qu9JgfF0vF76fupsRIG93yPSGLjgi6rwTi8yukDiDAg)
and then waits until the full document content is loaded from the y-websocket server before overlaying it on ProseMirror.
- secondTime with full document content
![图片](https://private-user-images.githubusercontent.com/41875799/283995911-eec1a02b-5923-4786-9289-11249a0e6efe.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM5NDcyNTUsIm5iZiI6MTcyMzk0Njk1NSwicGF0aCI6Ii80MTg3NTc5OS8yODM5OTU5MTEtZWVjMWEwMmItNTkyMy00Nzg2LTkyODktMTEyNDlhMGU2ZWZlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE4VDAyMDkxNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTVlZjhiOTBmODIyYjIyYzJiODhlMGI2NWE1OWRkYmY0N2Q0YTVhYTM1YWNiYzE3YWFjOWQ1MzA1NjhmMDQ2ZjEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.QzWKlc6cl4M4IFg5jbQfg-_kuCjlPLTLQp020PGyBkA)
Is there any plan from the official team to address this issue?
from y-websocket.
Related Issues (20)
- Callback object content is empty
- Could not find a declaration file for module 'y-websocket' HOT 3
- Offline modus or pending connect
- Extraneous updates where origin == null when using full reload
- how to detect the server side ping message
- Websocket closes on tab minify/switch after +/- 30s. How to handle?
- Server-side reloaded ydoc version is getting overwritten by client-side version upon page refresh
- Missing doc data binding when refreshing the page
- the new heap suddenly increase HOT 3
- how can I stop y-websocket-server? HOT 1
- Version 1.5.2 breaks y-websocket in the browser HOT 4
- Can't get text data on server HOT 6
- WebSocket connection to 'wss://localhost:9999/' failed HOT 1
- Persistance directory HOT 1
- "type":"module" / SyntaxError: Cannot use import statement outside a module
- cannot connect to y-websocket with node HOT 1
- yrb-actioncable sync awareness
- In bin/utils.js, closeConn(..) doesn't handle correctly if persistence is null HOT 1
- npx y-websocket does not work HOT 1
- How to verify permissions in websocket
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from y-websocket.