{"action":"opened","issue":{"url":"https://api.github.com/repos/realm/realm-cocoa/issues/4345","repository_url":"https://api.github.com/repos/realm/realm-cocoa","labels_url":"https://api.github.com/repos/realm/realm-cocoa/issues/4345/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-cocoa/issues/4345/comments","events_url":"https://api.github.com/repos/realm/realm-cocoa/issues/4345/events","html_url":"https://github.com/realm/realm-cocoa/issues/4345","id":190476250,"number":4345,"title":"realm::LogicError: Bad version number when calling `refresh` method.","user":{"login":"devedbox","id":8072556,"avatar_url":"https://avatars.githubusercontent.com/u/8072556?v=3","gravatar_id":"","url":"https://api.github.com/users/devedbox","html_url":"https://github.com/devedbox","followers_url":"https://api.github.com/users/devedbox/followers","following_url":"https://api.github.com/users/devedbox/following{/other_user}","gists_url":"https://api.github.com/users/devedbox/gists{/gist_id}","starred_url":"https://api.github.com/users/devedbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devedbox/subscriptions","organizations_url":"https://api.github.com/users/devedbox/orgs","repos_url":"https://api.github.com/users/devedbox/repos","events_url":"https://api.github.com/users/devedbox/events{/privacy}","received_events_url":"https://api.github.com/users/devedbox/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-11-19T04:36:47Z","updated_at":"2016-11-19T04:36:47Z","closed_at":null,"body":"## Goals\r\n\r\nNo error occurs.\r\n\r\n## Expected Results\r\n\r\nReturn with a expected when calling `refresh` method rather than an exception.\r\nIn version 2.0.4 and blow, the code works just fine. But failed in version 2.1.0.\r\n\r\n## Actual Results\r\n\r\nThe console logs:\r\n```\r\nlibc++abi.dylib: terminating with uncaught exception of type realm::LogicError: Bad version number\r\n```\r\n```\r\n(lldb) bt\r\n* thread #1: tid = 0x241ea1, 0x000000011440e867 libc++abi.dylib`__cxa_throw, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1\r\n    frame #0: 0x000000011440e867 libc++abi.dylib`__cxa_throw\r\n  * frame #1: 0x000000010ffa9d9c Realm`void realm::SharedGroup::advance_read<(anonymous namespace)::TransactLogValidator>(this=0x00007ffb15052a00, observer=0x00007fff52b92818, version_id=(version = 82, index = 1))::TransactLogValidator*, realm::VersionID) + 220 at group_shared.hpp:915\r\n    frame #2: 0x000000010ffa9cab Realm`void realm::_impl::SharedGroupFriend::advance_read<(anonymous namespace)::TransactLogValidator>(sg=0x00007ffb15052a00, obs=0x00007fff52b92818, ver=(version = 82, index = 1))::TransactLogValidator*, realm::VersionID) + 59 at group_shared.hpp:1086\r\n    frame #3: 0x000000010ffa9c5b Realm`void realm::LangBindHelper::advance_read<(anonymous namespace)::TransactLogValidator>(sg=0x00007ffb15052a00, observer=0x00007fff52b92818, version=(version = 82, index = 1))::TransactLogValidator&&, realm::VersionID) + 59 at lang_bind_helper.hpp:335\r\n    frame #4: 0x000000010ffba87c Realm`auto realm::_impl::transaction::advance(this=0x00007fff52b92bd8, args=0x00007fff52b92818)::$_1::operator()<(anonymous namespace)::TransactLogValidator>((anonymous namespace)::TransactLogValidator&&) const + 108 at transact_log_handler.cpp:830\r\n    frame #5: 0x000000010ffba18e Realm`(anonymous namespace)::TransactLogObserver::TransactLogObserver<realm::_impl::transaction::advance(this=0x00007fff52b92be8, context=0x0000600000010240, sg=0x00007ffb15052a00, func=0x00007fff52b92bd8, schema_mode=Optional<realm::SchemaMode> @ 0x00007fff52b92bd0, notifiers=0x00007fff52b92d40)::$_1>(realm::BindingContext*, realm::SharedGroup&, realm::_impl::transaction::advance(realm::SharedGroup&, realm::BindingContext*, realm::SchemaMode, realm::_impl::NotifierPackage&)::$_1&&, realm::util::Optional<realm::SchemaMode>, realm::_impl::NotifierPackage&) + 1022 at transact_log_handler.cpp:274\r\n    frame #6: 0x000000010ffa2a85 Realm`(anonymous namespace)::TransactLogObserver::TransactLogObserver<realm::_impl::transaction::advance(this=0x00007fff52b92be8, context=0x0000600000010240, sg=0x00007ffb15052a00, func=0x00007fff52b92bd8, schema_mode=<unavailable>, notifiers=0x00007fff52b92d40)::$_1>(realm::BindingContext*, realm::SharedGroup&, realm::_impl::transaction::advance(realm::SharedGroup&, realm::BindingContext*, realm::SchemaMode, realm::_impl::NotifierPackage&)::$_1&&, realm::util::Optional<realm::SchemaMode>, realm::_impl::NotifierPackage&) + 53 at transact_log_handler.cpp:262\r\n    frame #7: 0x000000010ffa2a3a Realm`realm::_impl::transaction::advance(sg=0x00007ffb15052a00, context=0x0000600000010240, schema_mode=Automatic, notifiers=0x00007fff52b92d40) + 138 at transact_log_handler.cpp:829\r\n    frame #8: 0x000000010fd6964a Realm`realm::_impl::RealmCoordinator::advance_to_latest(this=0x00007ffb13c11640, realm=0x00007ffb13e10f30) + 426 at realm_coordinator.cpp:697\r\n    frame #9: 0x000000010ff4c6da Realm`realm::Realm::refresh(this=0x00007ffb13e10f30) + 170 at shared_realm.cpp:596\r\n    frame #10: 0x000000010fefd14e Realm`::-[RLMRealm refresh](self=0x00006080000abac0, _cmd=\"refresh\") + 46 at RLMRealm.mm:570\r\n    frame #11: 0x000000010e521170 AXHTTPClient`-[AXHTTPClient handleRequestSuccessWithResponseObject:options:shouldStoreToRealm:requestDuration:compltion:](self=0x00006080001ea900, _cmd=\"handleRequestSuccessWithResponseObject:options:shouldStoreToRealm:requestDuration:compltion:\", object=4 key/value pairs, options=0x000060800022c820, storeToRealm=YES, duration=0.055444002151489258, completion=0x000000010d1f18b0) + 6464 at AXHTTPClient.m:453\r\n    frame #12: 0x000000010e51c3f6 AXHTTPClient`__31-[AXHTTPClient GET:completion:]_block_invoke((null)=0x0000600000c6aa80, task=0x00007ffb13c17c50, responseObject=4 key/value pairs) + 310 at AXHTTPClient.m:217\r\n    frame #13: 0x000000010dfcabc4 AFNetworking`__116-[AFHTTPSessionManager dataTaskWithHTTPMethod:URLString:parameters:uploadProgress:downloadProgress:success:failure:]_block_invoke.97((null)=<unavailable>, response=0x000060800023f820, responseObject=4 key/value pairs, error=0x0000000000000000) + 228 at AFHTTPSessionManager.m:287\r\n    frame #14: 0x000000010dfed759 AFNetworking`__72-[AFURLSessionManagerTaskDelegate URLSession:task:didCompleteWithError:]_block_invoke_2.150((null)=<unavailable>) + 201 at AFURLSessionManager.m:308\r\n    frame #15: 0x0000000114f57980 libdispatch.dylib`_dispatch_call_block_and_release + 12\r\n    frame #16: 0x0000000114f810cd libdispatch.dylib`_dispatch_client_callout + 8\r\n    frame #17: 0x0000000114f61a1d libdispatch.dylib`_dispatch_main_queue_callback_4CF + 733\r\n    frame #18: 0x00000001138a34f9 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9\r\n    frame #19: 0x0000000113868f8d CoreFoundation`__CFRunLoopRun + 2205\r\n    frame #20: 0x0000000113868494 CoreFoundation`CFRunLoopRunSpecific + 420\r\n    frame #21: 0x0000000116f3ea6f GraphicsServices`GSEventRunModal + 161\r\n    frame #22: 0x0000000110869964 UIKit`UIApplicationMain + 159\r\n    frame #23: 0x000000010d169bff ExchangeStreet`main(argc=1, argv=0x00007fff52b94608) + 111 at main.m:14\r\n    frame #24: 0x0000000114fcd68d libdyld.dylib`start + 1\r\n    frame #25: 0x0000000114fcd68d libdyld.dylib`start + 1\r\n```\r\n```\r\n(lldb) po [NSThread callStackSymbols]\r\n<_NSCallStackArray 0x600000247980>(\r\n0   ???                                 0x000000012cb21a17 0x0 + 5044836887,\r\n1   ExchangeStreet                      0x000000010d169b90 main + 0,\r\n2   Realm                               0x000000010ffa9cab _ZN5realm5_impl17SharedGroupFriend12advance_readIN12_GLOBAL__N_120TransactLogValidatorEEEvRNS_11SharedGroupEPT_NS_9VersionIDE + 59,\r\n3   Realm                               0x000000010ffa9c5b _ZN5realm14LangBindHelper12advance_readIN12_GLOBAL__N_120TransactLogValidatorEEEvRNS_11SharedGroupEOT_NS_9VersionIDE + 59,\r\n4   Realm                               0x000000010ffba87c _ZZN5realm5_impl11transaction7advanceERNS_11SharedGroupEPNS_14BindingContextENS_10SchemaModeERNS0_15NotifierPackageEENK3$_1clIJN12_GLOBAL__N_120TransactLogValidatorEEEEDaDpOT_ + 108,\r\n5   Realm                               0x000000010ffba18e _ZN12_GLOBAL__N_119TransactLogObserverC2IZN5realm5_impl11transaction7advanceERNS2_11SharedGroupEPNS2_14BindingContextENS2_10SchemaModeERNS3_15NotifierPackageEE3$_1EES8_S6_OT_NS2_4util8OptionalIS9_EESB_ + 1022,\r\n6   Realm                               0x000000010ffa2a85 _ZN12_GLOBAL__N_119TransactLogObserverC1IZN5realm5_impl11transaction7advanceERNS2_11SharedGroupEPNS2_14BindingContextENS2_10SchemaModeERNS3_15NotifierPackageEE3$_1EES8_S6_OT_NS2_4util8OptionalIS9_EESB_ + 53,\r\n7   Realm                               0x000000010ffa2a3a _ZN5realm5_impl11transaction7advanceERNS_11SharedGroupEPNS_14BindingContextENS_10SchemaModeERNS0_15NotifierPackageE + 138,\r\n8   Realm                               0x000000010fd6964a _ZN5realm5_impl16RealmCoordinator17advance_to_latestERNS_5RealmE + 426,\r\n9   Realm                               0x000000010ff4c6da _ZN5realm5Realm7refreshEv + 170,\r\n10  Realm                               0x000000010fefd14e -[RLMRealm refresh] + 46,\r\n11  AXHTTPClient                        0x000000010e521170 -[AXHTTPClient handleRequestSuccessWithResponseObject:options:shouldStoreToRealm:requestDuration:compltion:] + 6464,\r\n12  AXHTTPClient                        0x000000010e51c3f6 __31-[AXHTTPClient GET:completion:]_block_invoke + 310,\r\n13  AFNetworking                        0x000000010dfcabc4 __116-[AFHTTPSessionManager dataTaskWithHTTPMethod:URLString:parameters:uploadProgress:downloadProgress:success:failure:]_block_invoke.97 + 228,\r\n14  AFNetworking                        0x000000010dfed759 __72-[AFURLSessionManagerTaskDelegate URLSession:task:didCompleteWithError:]_block_invoke_2.150 + 201,\r\n15  libdispatch.dylib                   0x0000000114f57980 _dispatch_call_block_and_release + 12,\r\n16  libdispatch.dylib                   0x0000000114f810cd _dispatch_client_callout + 8,\r\n17  libdispatch.dylib                   0x0000000114f61a1d _dispatch_main_queue_callback_4CF + 733,\r\n18  CoreFoundation                      0x00000001138a34f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9,\r\n19  CoreFoundation                      0x0000000113868f8d __CFRunLoopRun + 2205,\r\n20  CoreFoundation                      0x0000000113868494 CFRunLoopRunSpecific + 420,\r\n21  GraphicsServices                    0x0000000116f3ea6f GSEventRunModal + 161,\r\n22  UIKit                               0x0000000110869964 UIApplicationMain + 159,\r\n23  ExchangeStreet                      0x000000010d169bff main + 111,\r\n24  libdyld.dylib                       0x0000000114fcd68d start + 1\r\n)\r\n```\r\n## Steps to Reproduce\r\n\r\nStep 1: Get objects on main thread.\r\n![step1](http://ww2.sinaimg.cn/large/d2297bd2gw1f9xawcg4ilj21i205stdc.jpg)\r\nStep2: Begin write transcation on serial thread.\r\n![step2](http://ww4.sinaimg.cn/large/d2297bd2gw1f9xax2dqaoj21hm03gmzy.jpg)\r\nStep3: Back to main thread and call `refresh` method.\r\n![step3](http://ww4.sinaimg.cn/large/d2297bd2gw1f9xaxko4izj21e805q0wt.jpg)\r\nResults: Terminating with uncaught exception.\r\n![Results](http://ww3.sinaimg.cn/large/d2297bd2gw1f9xay1cpvij21ei0i8h0c.jpg)\r\n## Code Sample\r\n```\r\n[JY_RealmManager syncTransaction:^(RLMRealm * _Nonnull realm) {\r\n                        [realm addOrUpdateObjectsFromArray:responseObjects];\r\n                    } inRealm:realm];\r\n```\r\n```\r\n_queue = dispatch_queue_create(\"com.jiangyou.realm.transaction\", DISPATCH_QUEUE_SERIAL);\r\n\r\n- (void)syncTransaction:(JYRealmWriteTransactionBlock)transaction inRealm:(RLMRealm * _Nullable)realm {\r\n    dispatch_sync(_queue, ^{\r\n        @autoreleasepool {\r\n            @try {\r\n                [realm beginWriteTransaction];\r\n                if (transaction) {\r\n                    transaction(realm);\r\n                }\r\n                NSError *error;\r\n                [realm commitWriteTransaction:&error];\r\n            }\r\n            @catch (NSException *exception) {\r\n                NSLog(@\"realm数据库写入失败，异常信息：%@\", exception);\r\n            }\r\n            @finally {\r\n                if (realm.inWriteTransaction) {\r\n                    [realm commitWriteTransaction];\r\n                }\r\n                if (!realm.autorefresh) {\r\n                    [realm refresh];\r\n                }\r\n            }\r\n        }\r\n    });\r\n}\r\n```\r\n## Version of Realm and Tooling\r\n\r\n```\r\nProductName:\tMac OS X\r\nProductVersion:\t10.12.1\r\nBuildVersion:\t16B2555\r\n\r\n/Applications/Xcode.app/Contents/Developer\r\nXcode 8.1\r\nBuild version 8B62\r\n\r\n/usr/local/bin/pod\r\n1.1.1\r\nRealm (2.1.0)\r\n\r\n/bin/bash\r\nGNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)\r\n\r\n\r\n(not in use here)\r\n\r\n/usr/bin/git\r\ngit version 2.9.3 (Apple Git-75)\r\n```"}}
{"actor":{"display_login":"devedbox"}}