Skip to content

Commit 06aacec

Browse files
authored
[RKOTLIN-1114] Fix sync client config not applied (#1779)
1 parent b6f141f commit 06aacec

File tree

22 files changed

+237
-76
lines changed

22 files changed

+237
-76
lines changed

.github/workflows/include-static-analysis.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
run: ./gradlew ktlintCheck
3636

3737
- name: Stash Ktlint results
38+
if: always()
3839
run: |
3940
rm -rf /tmp/ktlint
4041
rm -rf /tmp/detekt
@@ -50,6 +51,7 @@ jobs:
5051
5152
- name: Publish Ktlint results
5253
uses: actions/upload-artifact@v4
54+
if: always()
5355
with:
5456
name: Ktlint Analyzer report
5557
path: /tmp/ktlint/*
@@ -85,7 +87,8 @@ jobs:
8587
- name: Run Detekt
8688
run: ./gradlew detekt
8789

88-
- name: Stash Detekt results
90+
- name: Stash Detekt results
91+
if: always()
8992
run: |
9093
rm -rf /tmp/detekt
9194
mkdir /tmp/detekt
@@ -99,6 +102,7 @@ jobs:
99102
100103
- name: Publish Detekt results
101104
uses: actions/upload-artifact@v4
105+
if: always()
102106
with:
103107
name: Detekt Analyzer report
104108
path: /tmp/detekt/*

.github/workflows/pr.yml

+25-9
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
key: jni-linux-lib-${{ needs.check-cache.outputs.packages-sha }}
123123

124124
- name: Setup Java 11
125-
uses: actions/setup-java@v3
125+
uses: actions/setup-java@v4
126126
with:
127127
distribution: ${{ vars.VERSION_JAVA_DISTRIBUTION }}
128128
java-version: ${{ vars.VERSION_JAVA }}
@@ -431,11 +431,15 @@ jobs:
431431
run: |-
432432
echo "::add-matcher::.github/problem-matchers/kotlin.json"
433433
434-
- name: Setup Java 17
434+
- name: Setup Java
435435
uses: actions/setup-java@v4
436436
with:
437437
distribution: ${{ vars.VERSION_JAVA_DISTRIBUTION }}
438-
java-version: '17'
438+
# JVM 17 is required for android-actions/setup-android@v3
439+
# Last version will be used and available globally. Other Java versions can be accessed through env variables with such specification as 'JAVA_HOME_{{ MAJOR_VERSION }}_{{ ARCHITECTURE }}'
440+
java-version: |
441+
17
442+
${{ vars.VERSION_JAVA }}
439443
440444
- name: Setup Gradle and task/dependency caching
441445
uses: gradle/actions/setup-gradle@v3
@@ -473,10 +477,14 @@ jobs:
473477
echo '#!/bin/bash\nccache clang++ "$@"%"' > /usr/local/bin/ccache-clang++
474478
475479
- name: Setup Android SDK
476-
uses: android-actions/setup-android@v2
477-
480+
env:
481+
JAVA_HOME: ${{ env.JAVA_HOME_17_ARM64 }}
482+
uses: android-actions/setup-android@v3
483+
478484
- name: Install NDK
479485
run: sdkmanager --install "ndk;${{ env.NDK_VERSION }}"
486+
env:
487+
JAVA_HOME: ${{ env.JAVA_HOME_17_ARM64 }}
480488

481489
# We cannot use artifacts as they cannot be shared between workflows, so use cache instead.
482490
- name: Setup build cache
@@ -543,11 +551,15 @@ jobs:
543551
with:
544552
submodules: "recursive"
545553

546-
- name: Setup Java 11
554+
- name: Setup Java
547555
uses: actions/setup-java@v4
548556
with:
549557
distribution: ${{ vars.VERSION_JAVA_DISTRIBUTION }}
550-
java-version: ${{ vars.VERSION_JAVA }}
558+
# JVM 17 is required for android-actions/setup-android@v3
559+
# Last version will be used and available globally. Other Java versions can be accessed through env variables with such specification as 'JAVA_HOME_{{ MAJOR_VERSION }}_{{ ARCHITECTURE }}'
560+
java-version: |
561+
17
562+
${{ vars.VERSION_JAVA }}
551563
552564
- name: Setup Gradle and task/dependency caching
553565
uses: gradle/actions/setup-gradle@v3
@@ -602,9 +614,13 @@ jobs:
602614
echo '#!/bin/bash\nccache clang++ "$@"%"' > /usr/local/bin/ccache-clang++
603615
604616
- name: Setup Android SDK
605-
uses: android-actions/setup-android@v2
606-
617+
uses: android-actions/setup-android@v3
618+
env:
619+
JAVA_HOME: ${{ env.JAVA_HOME_17_X64 }}
620+
607621
- name: Install NDK
622+
env:
623+
JAVA_HOME: ${{ env.JAVA_HOME_17_X64 }}
608624
run: sdkmanager --install "ndk;${{ env.NDK_VERSION }}"
609625

610626
- name: Build Android Base Test Apk

CHANGELOG.md

+22-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,30 @@
44
* None.
55

66
### Enhancements
7+
* Reduce the size of the local transaction log produced by creating objects, improving the performance of insertion-heavy transactions (Core issue [realm/realm-core#7734](https://github.com/realm/realm-core/pull/7734)).
8+
* Performance has been improved for range queries on integers and timestamps. Requires that you use the "BETWEEN" operation in RQL or the Query::between() method when you build the query. (Core issue [realm/realm-core#7785](https://github.com/realm/realm-core/pull/7785))
9+
* [Sync] Report the originating error that caused a client reset to occur. (Core issue [realm/realm-core#6154](https://github.com/realm/realm-core/issues/6154)).
10+
* [Sync] It is no longer an error to set a base url for an App with a trailing slash - for example, `https://services.cloud.mongodb.com/` instead of `https://services.cloud.mongodb.com` - before this change that would result in a 404 error from the server (Core issue [realm/realm-core#7791](https://github.com/realm/realm-core/pull/7791)).
11+
* [Sync] On Windows devices Device Sync will additionally look up SSL certificates in the Windows Trusted Root Certification Authorities certificate store when establishing a connection. (Core issue [realm/realm-core#7882](https://github.com/realm/realm-core/pull/7882))
712
* [Sync] Add support for switching users with `App.switchUser(User)`. (Issue [#1813](https://github.com/realm/realm-kotlin/issues/1813)/[RKOTLIN-1115](https://jira.mongodb.org/browse/RKOTLIN-1115)).
813

914
### Fixed
10-
* None.
15+
* Comparing a numeric property with an argument list containing a string would throw. (Core issue [realm/realm-core#7714](https://github.com/realm/realm-core/issues/7714), since v2.0.0).
16+
* After compacting, a file upgrade would be triggered. This could cause loss of data if schema mode is SoftResetFile (Core issue [realm/realm-core#7747](https://github.com/realm/realm-core/issues/7747), since v1.15.0).
17+
* Encrypted files on Windows had a maximum size of 2GB even on x64 due to internal usage of `off_t`, which is a 32-bit type on 64-bit Windows (Core issue [realm/realm-core#7698](https://github.com/realm/realm-core/pull/7698)).
18+
* The encryption code no longer behaves differently depending on the system page size, which should entirely eliminate a recurring source of bugs related to copying encrypted Realm files between platforms with different page sizes. One known outstanding bug was ([RNET-1141](https://github.com/realm/realm-dotnet/issues/3592)), where opening files on a system with a larger page size than the writing system would attempt to read sections of the file which had never been written to (Core issue [realm/realm-core#7698](https://github.com/realm/realm-core/pull/7698)).
19+
* There were several complicated scenarios which could result in stale reads from encrypted files in multiprocess scenarios. These were very difficult to hit and would typically lead to a crash, either due to an assertion failure or DecryptionFailure being thrown (Core issue [realm/realm-core#7698](https://github.com/realm/realm-core/pull/7698), since v1.8.0).
20+
* Encrypted files have some benign data races where we can memcpy a block of memory while another thread is writing to a limited range of it. It is logically impossible to ever read from that range when this happens, but Thread Sanitizer quite reasonably complains about this. We now perform a slower operations when running with TSan which avoids this benign race (Core issue [realm/realm-core#7698](https://github.com/realm/realm-core/pull/7698)).
21+
* Tokenizing strings for full-text search could pass values outside the range [-1, 255] to `isspace()`, which is undefined behavior (Core issue [realm/realm-core#7698](https://github.com/realm/realm-core/pull/7698), since the introduction of FTS).
22+
* Clearing a List of RealmAnys in an upgraded file would lead to an assertion failing (Core issue [realm/realm-core#7771](https://github.com/realm/realm-core/issues/7771), since v1.15.0)
23+
* You could get unexpected merge results when assigning to a nested collection (Core issue [realm/realm-core#7809](https://github.com/realm/realm-core/issues/7809), since v1.15.0)
24+
* Fixed removing backlinks from the wrong objects if the link came from a nested list, nested dictionary, top-level dictionary, or list of mixed, and the source table had more than 256 objects. This could manifest as `array_backlink.cpp:112: Assertion failed: int64_t(value >> 1) == key.value` when removing an object. (Core issue [realm/realm-core#7594](https://github.com/realm/realm-core/issues/7594), since Core v11 for dictionaries)
25+
* Fixed the collapse/rejoin of clusters which contained nested collections with links. This could manifest as `array.cpp:319: Array::move() Assertion failed: begin <= end [2, 1]` when removing an object. (Core issue [realm/realm-core#7839](https://github.com/realm/realm-core/issues/7839), since the introduction of nested collections in v1.15.0)
26+
* [Sync] Platform networking was not enabled even if setting `AppConfiguration.Builder.usePlatformNetworking`. (Issue [#1811](https://github.com/realm/realm-kotlin/issues/1811)/[RKOTLIN-1114](https://jira.mongodb.org/browse/RKOTLIN-1114)).
27+
* [Sync] Fix some client resets (such as migrating to flexible sync) potentially failing with AutoClientResetFailed if a new client reset condition (such as rolling back a flexible sync migration) occurred before the first one completed. (Core issue [realm/realm-core#7542](https://github.com/realm/realm-core/pull/7542), since v1.9.0)
28+
* [Sync] Fixed a change of mode from Strong to All when removing links from an embedded object that links to a tombstone. This affects sync apps that use embedded objects which have a `Lst<Mixed>` that contains a link to another top level object which has been deleted by another sync client (creating a tombstone locally). In this particular case, the switch would cause any remaining link removals to recursively delete the destination object if there were no other links to it. (Core issue [realm/realm-core#7828](https://github.com/realm/realm-core/issues/7828), since v1.15.0)
29+
* [Sync] `SyncSession.uploadAllLocalChanges` was inconsistent in how it handled commits which did not produce any changesets to upload. Previously it would sometimes complete immediately if all commits waiting to be uploaded were empty, and at other times it would wait for a server roundtrip. It will now always complete immediately. (Core issue [realm/realm-core#7796](https://github.com/realm/realm-core/pull/7796)).
30+
* [Sync] Sync client can crash if a session is resumed while the session is being suspended. (Core issue [realm/realm-core#7860](https://github.com/realm/realm-core/issues/7860), since v1.0.0)
1131

1232
### Compatibility
1333
* File format: Generates Realms with file format v24 (reads and upgrades file format v10 or later).
@@ -25,7 +45,7 @@
2545
* Minimum R8: 8.0.34.
2646

2747
### Internal
28-
* None.
48+
* Updated to Realm Core 14.10.4 commit 4f83c590c4340dd7760d5f070e2e81613eb536aa.
2949

3050

3151
## 2.1.1-SNAPSHOT (YYYY-MM-DD)

packages/cinterop/src/commonMain/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt

+3-6
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,6 @@ expect object RealmInterop {
519519
// App
520520
fun realm_app_get(
521521
appConfig: RealmAppConfigurationPointer,
522-
syncClientConfig: RealmSyncClientConfigurationPointer,
523522
basePath: String,
524523
): RealmAppPointer
525524
fun realm_app_get_current_user(app: RealmAppPointer): RealmUserPointer?
@@ -600,8 +599,7 @@ expect object RealmInterop {
600599
fun realm_user_refresh_custom_data(app: RealmAppPointer, user: RealmUserPointer, callback: AppCallback<Unit>)
601600

602601
// Sync client config
603-
fun realm_sync_client_config_new(): RealmSyncClientConfigurationPointer
604-
602+
fun realm_app_config_get_sync_client_config(configPointer: RealmAppConfigurationPointer): RealmSyncClientConfigurationPointer
605603
fun realm_sync_client_config_set_default_binding_thread_observer(
606604
syncClientConfig: RealmSyncClientConfigurationPointer,
607605
appId: String
@@ -652,6 +650,8 @@ expect object RealmInterop {
652650
user: RealmUserPointer,
653651
partition: String
654652
): RealmSyncConfigurationPointer
653+
// Flexible Sync
654+
fun realm_flx_sync_config_new(user: RealmUserPointer): RealmSyncConfigurationPointer
655655
fun realm_sync_config_set_error_handler(
656656
syncConfig: RealmSyncConfigurationPointer,
657657
errorHandler: SyncErrorCallback
@@ -789,9 +789,6 @@ expect object RealmInterop {
789789
syncConfiguration: RealmSyncConfigurationPointer
790790
)
791791

792-
// Flexible Sync
793-
fun realm_flx_sync_config_new(user: RealmUserPointer): RealmSyncConfigurationPointer
794-
795792
// Flexible Sync Subscription
796793
fun realm_sync_subscription_id(subscription: RealmSubscriptionPointer): ObjectId
797794
fun realm_sync_subscription_name(subscription: RealmSubscriptionPointer): String?

packages/cinterop/src/jvm/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,6 @@ actual object RealmInterop {
11541154

11551155
actual fun realm_app_get(
11561156
appConfig: RealmAppConfigurationPointer,
1157-
syncClientConfig: RealmSyncClientConfigurationPointer,
11581157
basePath: String
11591158
): RealmAppPointer {
11601159
return LongPointerWrapper(realmc.realm_app_create(appConfig.cptr()), managed = true)
@@ -1314,8 +1313,9 @@ actual object RealmInterop {
13141313
)
13151314
}
13161315

1317-
actual fun realm_sync_client_config_new(): RealmSyncClientConfigurationPointer {
1318-
return LongPointerWrapper(realmc.realm_sync_client_config_new())
1316+
actual fun realm_app_config_get_sync_client_config(configPointer: RealmAppConfigurationPointer): RealmSyncClientConfigurationPointer {
1317+
// The configuration is owned by Core so don't track and release it through garbage collection of the NativePointer
1318+
return LongPointerWrapper(realmc.realm_app_config_get_sync_client_config(configPointer.cptr()), false)
13191319
}
13201320

13211321
actual fun realm_sync_client_config_set_default_binding_thread_observer(syncClientConfig: RealmSyncClientConfigurationPointer, appId: String) {
@@ -1762,6 +1762,10 @@ actual object RealmInterop {
17621762
}
17631763
}
17641764

1765+
actual fun realm_flx_sync_config_new(user: RealmUserPointer): RealmSyncConfigurationPointer {
1766+
return LongPointerWrapper<RealmSyncConfigT>(realmc.realm_flx_sync_config_new(user.cptr()))
1767+
}
1768+
17651769
actual fun realm_config_set_sync_config(realmConfiguration: RealmConfigurationPointer, syncConfiguration: RealmSyncConfigurationPointer) {
17661770
realmc.realm_config_set_sync_config(realmConfiguration.cptr(), syncConfiguration.cptr())
17671771
}
@@ -1984,10 +1988,6 @@ actual object RealmInterop {
19841988
realmc.realm_object_delete(obj.cptr())
19851989
}
19861990

1987-
actual fun realm_flx_sync_config_new(user: RealmUserPointer): RealmSyncConfigurationPointer {
1988-
return LongPointerWrapper(realmc.realm_flx_sync_config_new(user.cptr()))
1989-
}
1990-
19911991
actual fun realm_sync_subscription_id(subscription: RealmSubscriptionPointer): ObjectId {
19921992
val nativeBytes: ShortArray = realmc.realm_sync_subscription_id(subscription.cptr()).bytes
19931993
val byteArray = ByteArray(nativeBytes.size)

packages/cinterop/src/nativeDarwin/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,6 @@ actual object RealmInterop {
20622062

20632063
actual fun realm_app_get(
20642064
appConfig: RealmAppConfigurationPointer,
2065-
syncClientConfig: RealmSyncClientConfigurationPointer,
20662065
basePath: String
20672066
): RealmAppPointer {
20682067
return CPointerWrapper(realm_wrapper.realm_app_create(appConfig.cptr()), managed = true)
@@ -2469,8 +2468,9 @@ actual object RealmInterop {
24692468
)
24702469
}
24712470

2472-
actual fun realm_sync_client_config_new(): RealmSyncClientConfigurationPointer {
2473-
return CPointerWrapper(realm_wrapper.realm_sync_client_config_new())
2471+
actual fun realm_app_config_get_sync_client_config(configPointer: RealmAppConfigurationPointer): RealmSyncClientConfigurationPointer {
2472+
// The configuration is owned by Core so don't track and release it through garbage collection of the NativePointer
2473+
return CPointerWrapper(realm_wrapper.realm_app_config_get_sync_client_config(configPointer.cptr()), false)
24742474
}
24752475

24762476
actual fun realm_sync_client_config_set_default_binding_thread_observer(
@@ -3321,6 +3321,10 @@ actual object RealmInterop {
33213321
}
33223322
}
33233323

3324+
actual fun realm_flx_sync_config_new(user: RealmUserPointer): RealmSyncConfigurationPointer {
3325+
return CPointerWrapper<RealmSyncConfigT>(realm_wrapper.realm_flx_sync_config_new((user.cptr())))
3326+
}
3327+
33243328
actual fun realm_app_sync_client_reconnect(app: RealmAppPointer) {
33253329
realm_wrapper.realm_app_sync_client_reconnect(app.cptr())
33263330
}
@@ -3336,10 +3340,6 @@ actual object RealmInterop {
33363340
realm_wrapper.realm_config_set_sync_config(realmConfiguration.cptr(), syncConfiguration.cptr())
33373341
}
33383342

3339-
actual fun realm_flx_sync_config_new(user: RealmUserPointer): RealmSyncConfigurationPointer {
3340-
return CPointerWrapper(realm_wrapper.realm_flx_sync_config_new((user.cptr())))
3341-
}
3342-
33433343
actual fun realm_sync_subscription_id(subscription: RealmSubscriptionPointer): ObjectId {
33443344
return ObjectId(realm_wrapper.realm_sync_subscription_id(subscription.cptr()).getBytes())
33453345
}

packages/external/core

Submodule core updated 267 files

packages/jni-swig-stub/realm.i

-2
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,6 @@ $result = SWIG_JavaArrayOutLonglong(jenv, (long long *)result, 2);
533533
%ignore "realm_dictionary_add_notification_callback";
534534
%ignore "realm_results_add_notification_callback";
535535

536-
%ignore "realm_app_config_get_sync_client_config";
537-
538536
// Swig doesn't understand __attribute__ so eliminate it
539537
#define __attribute__(x)
540538

packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/exceptions/SyncExceptions.kt

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public open class UnrecoverableSyncException internal constructor(message: Strin
6868
* Thrown when the type of sync used by the server does not match the one used by the client, i.e.
6969
* the server and client disagrees whether to use Partition-based or Flexible Sync.
7070
*/
71+
@Suppress("DEPRECATION")
7172
public class WrongSyncTypeException internal constructor(message: String) :
7273
UnrecoverableSyncException(message)
7374

packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/AppConfigurationImpl.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ public class AppConfigurationImpl @OptIn(ExperimentalKBsonSerializerApi::class)
8989
applicationInfo = info.toString()
9090
}
9191
val sdkInfo = "RealmKotlin/$SDK_VERSION"
92+
9293
val synClientConfig: RealmSyncClientConfigurationPointer = initializeSyncClientConfig(
94+
appConfigPointer,
9395
websocketTransport,
9496
sdkInfo,
9597
applicationInfo.toString()
@@ -101,7 +103,6 @@ public class AppConfigurationImpl @OptIn(ExperimentalKBsonSerializerApi::class)
101103
websocketTransport,
102104
RealmInterop.realm_app_get(
103105
appConfigPointer,
104-
synClientConfig,
105106
appFilesDirectory()
106107
)
107108
)
@@ -158,11 +159,12 @@ public class AppConfigurationImpl @OptIn(ExperimentalKBsonSerializerApi::class)
158159
}
159160

160161
private fun initializeSyncClientConfig(
162+
appConfigPointer: RealmAppConfigurationPointer,
161163
webSocketTransport: WebSocketTransport?,
162164
sdkInfo: String?,
163165
applicationInfo: String?
164166
): RealmSyncClientConfigurationPointer =
165-
RealmInterop.realm_sync_client_config_new()
167+
RealmInterop.realm_app_config_get_sync_client_config(appConfigPointer)
166168
.also { syncClientConfig ->
167169
// Initialize client configuration first
168170
RealmInterop.realm_sync_client_config_set_default_binding_thread_observer(syncClientConfig, appId)

0 commit comments

Comments
 (0)