Title: ByteArrayProxy data corruption due to pointer getting GC'd? · Issue #252 · lmdbjava/lmdbjava · GitHub
Open Graph Title: ByteArrayProxy data corruption due to pointer getting GC'd? · Issue #252 · lmdbjava/lmdbjava
X Title: ByteArrayProxy data corruption due to pointer getting GC'd? · Issue #252 · lmdbjava/lmdbjava
Description: Hey, I've encountered an issue similar to this one: #207 . One key difference is that I use ByteArrayProxy instead of any direct buffers. I'm using the newest lmdbjava along with lmdb binary built from newest version (commit). So I've be...
Open Graph Description: Hey, I've encountered an issue similar to this one: #207 . One key difference is that I use ByteArrayProxy instead of any direct buffers. I'm using the newest lmdbjava along with lmdb binary built ...
X Description: Hey, I've encountered an issue similar to this one: #207 . One key difference is that I use ByteArrayProxy instead of any direct buffers. I'm using the newest lmdbjava along with lmdb binar...
Opengraph URL: https://github.com/lmdbjava/lmdbjava/issues/252
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ByteArrayProxy data corruption due to pointer getting GC'd?","articleBody":"Hey, I've encountered an issue similar to this one: https://github.com/lmdbjava/lmdbjava/issues/207 . One key difference is that I use `ByteArrayProxy` instead of any direct buffers. \n\nI'm using the newest lmdbjava along with lmdb binary built from newest version ([commit](https://github.com/LMDB/lmdb/commit/f20e41de09d97e4461946b7e26ec831d0c24fac7)).\n\nSo I've been following the steps from the mentioned issue and it's true that adding `System.gc()` call right before `mdb_put` makes the bug more frequent. I've been looking at the implementation of the `ByteArrayProxy` and one thing caught my attention. Here's the code from it:\n\n```java\n @Override\n protected void in(final byte[] buffer, final Pointer ptr, final long ptrAddr) {\n final Pointer pointer = MEM_MGR.allocateDirect(buffer.length);\n pointer.put(0, buffer, 0, buffer.length);\n ptr.putLong(STRUCT_FIELD_OFFSET_SIZE, buffer.length);\n ptr.putAddress(STRUCT_FIELD_OFFSET_DATA, pointer.address());\n }\n\n```\nWhat worries me is that the `pointer`'s underlying memory lifespan is actually longer than the `pointer` reference itself. From my understanding of how `TransientNativeMemory` in `jnr-ffi` works, once a `Pointer` has no reference to it, it's subject to be cleared by the \"cleaner\" thread. So there's a slim chance of `mdb_put` operating on memory that has been cleared already. Am I correct?\n\nWhat I'm currently testing is adding a static list of references to pointers inside the proxy, and then manually clearing it once transaction is done: https://github.com/bdsystems/lmdbjava/commit/9e5eee9926b2cd80efb2235de22a166d71779480 \nSo far this seems to work correctly, but with these kind of issues testing has to take time.\n\nWhat do you think? Could that be the bug, or is my hypothesis wrong? I'm new to java memory management and jnr-ffi in particular so please correct me if my reasoning is faulty.","author":{"url":"https://github.com/oti-dev","@type":"Person","name":"oti-dev"},"datePublished":"2025-03-27T10:30:37.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/252/lmdbjava/issues/252"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b516e7b7-82c7-36c9-ff57-a91647c58315 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 95EC:2946F1:64018EE:878161C:696E3C14 |
| html-safe-nonce | 330ecb90f3007839d6c4f8c2b03da6f15d4e916b51db2bc7a83176d7e8305726 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NUVDOjI5NDZGMTo2NDAxOEVFOjg3ODE2MUM6Njk2RTNDMTQiLCJ2aXNpdG9yX2lkIjoiODQxMjA3NjIzMTM1NTE1MzQyOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | da14f77212c209809cebb107d1d707203c135488be3ba6d04f90902ebdf4397f |
| hovercard-subject-tag | issue:2952409649 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/lmdbjava/lmdbjava/252/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bdffb639aabadab7fb6a74ace152cb90c5ae0bb420d416c12d4518bcd9780c26/lmdbjava/lmdbjava/issues/252 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bdffb639aabadab7fb6a74ace152cb90c5ae0bb420d416c12d4518bcd9780c26/lmdbjava/lmdbjava/issues/252 |
| og:image:alt | Hey, I've encountered an issue similar to this one: #207 . One key difference is that I use ByteArrayProxy instead of any direct buffers. I'm using the newest lmdbjava along with lmdb binary built ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | oti-dev |
| hostname | github.com |
| expected-hostname | github.com |
| None | b39958d54b39d52b9fc890ff25687d2383a83e003512d4480499b2dbd046839f |
| turbo-cache-control | no-preview |
| go-import | github.com/lmdbjava/lmdbjava git https://github.com/lmdbjava/lmdbjava.git |
| octolytics-dimension-user_id | 19765602 |
| octolytics-dimension-user_login | lmdbjava |
| octolytics-dimension-repository_id | 60480511 |
| octolytics-dimension-repository_nwo | lmdbjava/lmdbjava |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 60480511 |
| octolytics-dimension-repository_network_root_nwo | lmdbjava/lmdbjava |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | fba10be4ea34590240b2f4a625fc807362c2d5b8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width