{"action":"created","issue":{"url":"https://api.github.com/repos/ReactiveX/RxJava/issues/1139","repository_url":"https://api.github.com/repos/ReactiveX/RxJava","labels_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/1139/labels{/name}","comments_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/1139/comments","events_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/1139/events","html_url":"https://github.com/ReactiveX/RxJava/issues/1139","id":32565894,"number":1139,"title":"Weird Issue with SubscribeOn and Schedulers","user":{"login":"pequnio3","id":1223946,"avatar_url":"https://avatars.githubusercontent.com/u/1223946?v=3","gravatar_id":"","url":"https://api.github.com/users/pequnio3","html_url":"https://github.com/pequnio3","followers_url":"https://api.github.com/users/pequnio3/followers","following_url":"https://api.github.com/users/pequnio3/following{/other_user}","gists_url":"https://api.github.com/users/pequnio3/gists{/gist_id}","starred_url":"https://api.github.com/users/pequnio3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pequnio3/subscriptions","organizations_url":"https://api.github.com/users/pequnio3/orgs","repos_url":"https://api.github.com/users/pequnio3/repos","events_url":"https://api.github.com/users/pequnio3/events{/privacy}","received_events_url":"https://api.github.com/users/pequnio3/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2014-04-30T19:29:25Z","updated_at":"2016-05-27T07:21:33Z","closed_at":"2014-07-24T06:53:15Z","body":"Hio,\r\n\r\nI'm using Rx ina function to perform batched batch-writes to a database we are using.  I have a class which performs this functionality and uses subscribeOn with an executor pool to perform these operations.\r\n\r\nI'm running into a situation where the below function ends up hanging and I believe it hangs due to my subscribeOn usage because when I take out subscribeOn, I'm able to reach the flat map following it, but unable to reach that code when subscribeOn is left in.\r\n\r\n```java\r\nprotected Observable<SherpaBatchWriteResponse> performBatchWriteOnBatchedRecords(final Observable<IDataRecord> encryptedRecordsObs) {\r\nListeningExecutorService executorService = MoreExecutors.listeningDecorator(new ThreadPoolExecutor(10, 10, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()));\r\nreturn encryptedRecordsObs\r\n                .buffer(MAX_BATCH_SET_RECORDS)\r\n                .subscribeOn(Schedulers.executor(executorService))\r\n                .flatMap(new Func1<List<IDataRecord>, Observable<SherpaBatchWriteResponse>>() {\r\n                    @Override\r\n                    public Observable<SherpaBatchWriteResponse> call(List<IDataRecord> writeRecords) {\r\n                        try {\r\n                            SherpaBWRequestItems[] items = createSherpaBatchWriteRequestItemsForDataRecords(writeRecords);\r\n                            return Observable.just(sherpaService.batchWriteRecords(items, (long) switchboardConfig.sherpaBatchGetTimeout()));\r\n                        } catch (SwitchboardException e) {\r\n                            return Observable.error(e);\r\n                        } catch (SherpaException e) {\r\n                            return Observable.error(new SwitchboardException(SwitchboardErrorCode.SHERPA_BATCH_WRITE_FAILED_TO_WRITE_SOME_RECORDS, e));\r\n                        }\r\n                    }\r\n                })\r\n```\r\n\r\n\r\nWhat also makes this situation weird is that I have two code paths that use this function, and one code path succeeds when using it while the other hangs.  Granted I believe both code paths get to the point where it should be called\r\n\r\nI have one code path that hangs that looks like\r\n\r\n```java\r\nperformBatchWriteOnBatchedRecords(Observable.from(Lists.newArrayList(record1,record2)))\r\n```\r\n\r\nwhere as a different code path succeeds that looks like\r\n\r\n```java\r\n// observable that emits idataRecords and the iDataRecords are fetched in with \r\n// observables via a network call\r\nObservable<IDataRecord> async = getRecordsAsync();\r\nperformBatchWriteOnBatchedRecords(async)\r\n```\r\n\r\nDo you have any idea why this may be happening or any pitfalls I may be falling into?\r\n\r\nI've created my own operator to run a specific map/flatmap function on a pool, so I've been able to overcome this, but I'm still interested on why subscribeOn was being goofy for me.\r\n\r\nThanks,\r\nBlake"},"comment":{"url":"https://api.github.com/repos/ReactiveX/RxJava/issues/comments/222077981","html_url":"https://github.com/ReactiveX/RxJava/issues/1139#issuecomment-222077981","issue_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/1139","id":222077981,"user":{"login":"bravekingzhang","id":4476322,"avatar_url":"https://avatars.githubusercontent.com/u/4476322?v=3","gravatar_id":"","url":"https://api.github.com/users/bravekingzhang","html_url":"https://github.com/bravekingzhang","followers_url":"https://api.github.com/users/bravekingzhang/followers","following_url":"https://api.github.com/users/bravekingzhang/following{/other_user}","gists_url":"https://api.github.com/users/bravekingzhang/gists{/gist_id}","starred_url":"https://api.github.com/users/bravekingzhang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bravekingzhang/subscriptions","organizations_url":"https://api.github.com/users/bravekingzhang/orgs","repos_url":"https://api.github.com/users/bravekingzhang/repos","events_url":"https://api.github.com/users/bravekingzhang/events{/privacy}","received_events_url":"https://api.github.com/users/bravekingzhang/received_events","type":"User","site_admin":false},"created_at":"2016-05-27T07:21:33Z","updated_at":"2016-05-27T07:21:33Z","body":"terrible"}}
{"actor":{"display_login":"bravekingzhang"}}