Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bindings/crypto-nodejs: after each receiveSyncChanges call, there is an empty KeysUploadRequest pending #800

Closed
Tracked by #236
turt2live opened this issue Jun 29, 2022 · 12 comments · Fixed by #812
Assignees
Labels

Comments

@turt2live
Copy link
Member

sample logs:

Wed, 29 Jun 2022 21:00:56 GMT [DEBUG] [MatrixClientLite] Performing sync with token s25976_489518_6_623_3309_168_5298_2809_1
Wed, 29 Jun 2022 21:00:56 GMT [DEBUG] [MatrixHttpClient] (REQ-38) GET http://localhost:8338/_matrix/client/v3/sync
Wed, 29 Jun 2022 21:00:56 GMT [DEBUG] [MatrixHttpClient] (REQ-38) qs = {"full_state":false,"timeout":30000,"since":"s25976_489518_6_623_3309_168_5298_2809_1"}
Wed, 29 Jun 2022 21:00:56 GMT [DEBUG] [MatrixHttpClient] (REQ-38 RESP-H200) {
  next_batch: 's25976_489519_6_623_3309_168_5298_2809_1',
  presence: { events: [ [Object] ] },
  device_one_time_keys_count: { signed_curve25519: 50 },
  'org.matrix.msc2732.device_unused_fallback_key_types': [],
  device_unused_fallback_key_types: []
}
Wed, 29 Jun 2022 21:00:56 GMT [DEBUG] [MatrixClientLite] Received sync. Next token: s25976_489519_6_623_3309_168_5298_2809_1
{}
Wed, 29 Jun 2022 21:00:56 GMT [DEBUG] [MatrixHttpClient] (REQ-39) POST http://localhost:8338/_matrix/client/v3/keys/upload
Wed, 29 Jun 2022 21:00:56 GMT [DEBUG] [MatrixHttpClient] (REQ-39) body = {"device_keys":null,"one_time_keys":{}}

The outgoing request should be omitted if there's nothing to actually upload.

@turt2live turt2live changed the title feat(bindings/crypto-nodejs): after each receiveSyncChanges call, there is an empty KeysUploadRequest pending bindings/crypto-nodejs: after each receiveSyncChanges call, there is an empty KeysUploadRequest pending Jun 29, 2022
@Hywan
Copy link
Member

Hywan commented Jun 30, 2022

I bet it's related to matrix-sdk-crypto itself as the Node.js binding simply forwards calls and data.

@poljar
Copy link
Contributor

poljar commented Jun 30, 2022

I wouldn't bet on that.

if device_keys.is_none() && one_time_keys.is_empty() && fallback_keys.is_empty() {

So we can see that the keys upload request will be None if there isn't anything to upload. One of those three will be Some.

We can also see that, when we convert the request to js, we don't seem to map the fallback key field:

request!(KeysUploadRequest from RumaKeysUploadRequest maps fields device_keys, one_time_keys);

So my bet is that we never upload the fallback key because we don't pass it to the js side, the machine rightfully so tries to upload it again on the next sync.

@poljar
Copy link
Contributor

poljar commented Jun 30, 2022

Come to think of, why doesn't that macro use serde_json::to_string() directly instead of mapping things manually. This deliberately loses data, which causes this bug.

It ends up converting the map to a string in the end anyways.

@Hywan Hywan self-assigned this Jun 30, 2022
@Hywan Hywan added the bindings label Jun 30, 2022
@turt2live
Copy link
Member Author

(exposing the fallback key would also be a great thing to have)

@poljar
Copy link
Contributor

poljar commented Jun 30, 2022

What do you mean by exposing?

@turt2live
Copy link
Member Author

fallback keys from a http standpoint are only two parts: /sync and /upload. We currently have /sync as part of the bindings, but not /upload (as your comment mentioned regarding the field disappearing between translations)

@poljar
Copy link
Contributor

poljar commented Jun 30, 2022

Ok in that case, not only is it a great thing, it's a necessary thing. That's the whole bug here, we don't and won't support not uploading the fallback key.

@turt2live
Copy link
Member Author

sorry, to rephrase: the intent is that the bindings will support fallback keys?

@poljar
Copy link
Contributor

poljar commented Jun 30, 2022

They have to support fallback keys, otherwise you end up uploading empty /keys/upload responses.

Yes, they will support fallback keys.

@Hywan
Copy link
Member

Hywan commented Jul 1, 2022

Come to think of, why doesn't that macro use serde_json::to_string() directly instead of mapping things manually. This deliberately loses data, which causes this bug.

It ends up converting the map to a string in the end anyways.

That's a good question. I guess I got inspired by the crypto-FFI binding itself:

KeysUpload(u) => {
let body = json!({
"device_keys": u.device_keys,
"one_time_keys": u.one_time_keys,
});
Request::KeysUpload {
request_id: r.request_id().to_string(),
body: serde_json::to_string(&body)
.expect("Can't serialize keys upload request"),
}
}

@poljar
Copy link
Contributor

poljar commented Jul 1, 2022

Come to think of, why doesn't that macro use serde_json::to_string() directly instead of mapping things manually. This deliberately loses data, which causes this bug.
It ends up converting the map to a string in the end anyways.

That's a good question. I guess I got inspired by the crypto-FFI binding itself:

KeysUpload(u) => {
let body = json!({
"device_keys": u.device_keys,
"one_time_keys": u.one_time_keys,
});
Request::KeysUpload {
request_id: r.request_id().to_string(),
body: serde_json::to_string(&body)
.expect("Can't serialize keys upload request"),
}
}

That's a good catch and I remembered why we don't serialize u there. Because Serialize is not implemented for it.

Let's fix this the ugly way for now and we'll have customized requests/responses that do implement Serialize later on. This will just be a continuation on #767.

@Hywan
Copy link
Member

Hywan commented Jul 4, 2022

That's a good catch and I remembered why we don't serialize u there. Because Serialize is not implemented for it.

Correct. Some types from matrix-sdk-crypto can implement Serialize quite easily, but for Ruma, there must be a reason why they aren't implementing Serialize and Deserialize.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants