# runtime_error_app **Repository Path**: kropachevpavel/runtime_error_app ## Basic Information - **Project Name**: runtime_error_app - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-09-23 - **Last Updated**: 2024-09-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Stack corruption in case of iteration over HashSet ## Backstory When working on the next version of the prefetcher library (it is a part of OHOS ArkUI kit) we faced with the stack corruption issue. ### Corrupted ```bash 09-23 14:31:23.938 55862-55862 A00000/com.huaw...lib-prefetch com.huawe...ocks_poc D [Prefetcher-1] Total count on fetch 750 registry state r2f: {"start":720,"end":741} missed: [722,724,725,726,727,728,729,730,733,734,735,736,737,738,739,740] evl count: 741 09-23 14:31:23.938 55862-55862 A00000/com.huaw...lib-prefetch com.huawe...ocks_poc I [Prefetcher-1] to fetch 740 09-23 14:31:23.939 55862-55862 A00000/com.huaw...lib-prefetch com.huawe...ocks_poc W [Prefetcher-1] Error in dangerous-diff: Error at anonymous (run_time_error/src/main/ets/prefetch/prefetcher.js:1199:1) at fetch (run_time_error/src/main/ets/prefetch/prefetcher.js:1163:1) at fetchedCallback (run_time_error/src/main/ets/prefetch/prefetcher.js:1230:1) ---unexpected call-- at anonymous (run_time_error/src/main/ets/prefetch/prefetcher.js:1205:1) at anonymous (run_time_error/src/main/ets/view/PrefectherDemoComponent.ets:196:7) at notifyBatchUpdate (run_time_error/src/main/ets/view/PrefectherDemoComponent.ets:195:5) at batchAdd (run_time_error/src/main/ets/view/PrefectherDemoComponent.ets:169:5) at anonymous (run_time_error/src/main/ets/view/PrefectherDemoComponent.ets:17:7) at anonymous (run_time_error/src/main/ets/prefetch/prefetcher.js:1189:1) at fetch (run_time_error/src/main/ets/prefetch/prefetcher.js:1163:1) at visibleAreaChangedInternal (run_time_error/src/main/ets/prefetch/prefetcher.js:1149:1) at visibleAreaChanged (run_time_error/src/main/ets/prefetch/prefetcher.js:1136:1) at visibleAreaChanged (run_time_error/src/main/ets/prefetch/prefetcher.js:142:1) at anonymous (run_time_error/src/main/ets/view/PrefectherDemoComponent.ets:35:7) ``` ### Correct ```bash 09-23 14:31:23.266 55862-55862 A00000/com.huaw...lib-prefetch com.huawe...ocks_poc D [Prefetcher-1] Total count on fetch 740 registry state r2f: {"start":710,"end":731} missed: [710,713,714,716,717,718,719,720,721,722,723,724,725,726,727,728,729,730] evl count: 741 09-23 14:31:23.267 55862-55862 A00000/com.huaw...lib-prefetch com.huawe...ocks_poc I [Prefetcher-1] to fetch 730 09-23 14:31:23.267 55862-55862 A00000/com.huaw...lib-prefetch com.huawe...ocks_poc W [Prefetcher-1] Error in dangerous-diff: Error at anonymous (run_time_error/src/main/ets/prefetch/prefetcher.js:1199:1) at fetch (run_time_error/src/main/ets/prefetch/prefetcher.js:1163:1) at batchUpdateInternal (run_time_error/src/main/ets/prefetch/prefetcher.js:1036:1) at batchUpdate (run_time_error/src/main/ets/prefetch/prefetcher.js:1004:1) at onDatasetChange (run_time_error/src/main/ets/prefetch/prefetcher.js:337:1) at anonymous (run_time_error/src/main/ets/view/PrefectherDemoComponent.ets:196:7) at notifyBatchUpdate (run_time_error/src/main/ets/view/PrefectherDemoComponent.ets:195:5) at batchAdd (run_time_error/src/main/ets/view/PrefectherDemoComponent.ets:169:5) at anonymous (run_time_error/src/main/ets/view/PrefectherDemoComponent.ets:17:7) at anonymous (run_time_error/src/main/ets/prefetch/prefetcher.js:1189:1) at fetch (run_time_error/src/main/ets/prefetch/prefetcher.js:1163:1) at visibleAreaChangedInternal (run_time_error/src/main/ets/prefetch/prefetcher.js:1149:1) at visibleAreaChanged (run_time_error/src/main/ets/prefetch/prefetcher.js:1136:1) at visibleAreaChanged (run_time_error/src/main/ets/prefetch/prefetcher.js:142:1) at anonymous (run_time_error/src/main/ets/view/PrefectherDemoComponent.ets:35:7) ``` The `error-logs` folder contains full logs of the issue. The `run_time_error` folder contains the demo application code that allows to reproduce the issue. ## Demo app description Demo app contains a list of an unlimited size. The list contains colored rectangles. Main app component code resides in the `run_time_error/src/main/ets/view/PrefectherDemoComponent.ets` file. ```typescript // PrefectherDemoComponent.ets import { createPrefetcher } from '@netteam/prefetcher'; @Component export struct PrefetcherDemoComponent { private readonly dataSource = new SimulationDataSource(); private readonly prefetcher = createPrefetcher({ logger: new Logger() }).withDataSource(this.dataSource) .onLoadMore(() => { this.dataSource.batchAdd(this.dataSource.totalCount(), PAGE_SIZE); }) .onMainThread() .withAgent(new FetchAgent()); build() { WaterFlow() {...} //... } ``` To display list of rectangles a `WaterFlow` component is used. It is linked to the data source. During scrolling prefetcher library, this is our product, calls a callback in which new items are added to the data source collection. See line 17 of `PrefectherDemoComponent.ets`. The callback code is fully synchronous. `SimulationDataSource` is a data source that is linked to prefetcher and to the `LazyForEach` component. `FetchAgent` class simulates fetching of image with an additional delay. The delay is in range [200, 1200] ms. `PictureItem` class is a data source item that satisfies `IDataReferenceItem` interface defined in the prefetcher library. As a fetch payload - information for the fetch agent it returns color code. As a result of fetch it accepts pixel map for `Image`. `PictureItemComponent` wraps each `PictureItem` and allows to display an image after the picture is ready. ## Error reproduction 1. Start the application 2. Scroll down 3. At some moment you are unable to scroll further down The reason Stack corruption. In logs you will see call stack specified above. As a result app state is corrupted and we see the observed behavior.