Skip to content

Commit b9eb407

Browse files
committed
fix: revert 3a2d528 to fix 'incorrect data check' error.
This error could occour in heavily threaded code for unknown reason. But maybe it's due to threads somehow not cleaning up their reused decompressor properly (maybe related to the zlib-ng version). It's strange and sad as this really costs performnace for no good reason.
1 parent 5861afb commit b9eb407

File tree

2 files changed

+54
-36
lines changed

2 files changed

+54
-36
lines changed

gix-pack/src/cache/delta/traverse/resolve.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -409,18 +409,29 @@ fn set_len(v: &mut Vec<u8>, new_len: usize) {
409409

410410
fn decompress_all_at_once_with(b: &[u8], decompressed_len: usize, out: &mut Vec<u8>) -> Result<(), Error> {
411411
set_len(out, decompressed_len);
412-
use std::cell::RefCell;
413-
thread_local! {
414-
pub static INFLATE: RefCell<zlib::Inflate> = RefCell::new(zlib::Inflate::default());
415-
}
416-
417-
INFLATE.with(|inflate| {
418-
let mut inflate = inflate.borrow_mut();
419-
inflate.reset();
420-
inflate.once(b, out).map_err(|err| Error::ZlibInflate {
412+
// TODO: try to put this back after the next zlib-ng upgrade.
413+
// This is from 3a2d5286084597d4c68549903709cda77dda4357 and it worked until zlib-ng-sys 1.1.9. Then it started to
414+
// fail with `incorrect data check` 25% of the time.
415+
// Note that thread_local! usage was also removed in two other places in `decode/entry.rs` for good measure.
416+
// use std::cell::RefCell;
417+
// thread_local! {
418+
// pub static INFLATE: RefCell<zlib::Inflate> = RefCell::new(zlib::Inflate::default());
419+
// }
420+
//
421+
// INFLATE.with(|inflate| {
422+
// let mut inflate = inflate.borrow_mut();
423+
// let res = inflate.once(b, out).map_err(|err| Error::ZlibInflate {
424+
// source: err,
425+
// message: "Failed to decompress entry",
426+
// });
427+
// inflate.reset();
428+
// res
429+
// })?;
430+
zlib::Inflate::default()
431+
.once(b, out)
432+
.map_err(|err| Error::ZlibInflate {
421433
source: err,
422434
message: "Failed to decompress entry",
423-
})
424-
})?;
435+
})?;
425436
Ok(())
426437
}

gix-pack/src/data/file/decode/entry.rs

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,21 @@ impl File {
126126
let offset: usize = data_offset.try_into().expect("offset representable by machine");
127127
assert!(offset < self.data.len(), "entry offset out of bounds");
128128

129-
use std::cell::RefCell;
130-
thread_local! {
131-
pub static INFLATE: RefCell<zlib::Inflate> = RefCell::new(zlib::Inflate::default());
132-
}
133-
INFLATE.with(|inflate| {
134-
let mut inflate = inflate.borrow_mut();
135-
let res = inflate
136-
.once(&self.data[offset..], out)
137-
.map(|(_status, consumed_in, _consumed_out)| consumed_in);
138-
inflate.reset();
139-
res
140-
})
129+
// use std::cell::RefCell;
130+
// thread_local! {
131+
// pub static INFLATE: RefCell<zlib::Inflate> = RefCell::new(zlib::Inflate::default());
132+
// }
133+
// INFLATE.with(|inflate| {
134+
// let mut inflate = inflate.borrow_mut();
135+
// let res = inflate
136+
// .once(&self.data[offset..], out)
137+
// .map(|(_status, consumed_in, _consumed_out)| consumed_in);
138+
// inflate.reset();
139+
// res
140+
// })
141+
zlib::Inflate::default()
142+
.once(&self.data[offset..], out)
143+
.map(|(_status, consumed_in, _consumed_out)| consumed_in)
141144
}
142145

143146
/// Like `decompress_entry_from_data_offset`, but returns consumed input and output.
@@ -149,19 +152,23 @@ impl File {
149152
let offset: usize = data_offset.try_into().expect("offset representable by machine");
150153
assert!(offset < self.data.len(), "entry offset out of bounds");
151154

152-
use std::cell::RefCell;
153-
thread_local! {
154-
pub static INFLATE: RefCell<zlib::Inflate> = RefCell::new(zlib::Inflate::default());
155-
}
156-
157-
INFLATE.with(|inflate| {
158-
let mut inflate = inflate.borrow_mut();
159-
let res = inflate
160-
.once(&self.data[offset..], out)
161-
.map(|(_status, consumed_in, consumed_out)| (consumed_in, consumed_out));
162-
inflate.reset();
163-
res
164-
})
155+
// TODO: put this back in once we know that zlib-ng doesn't fail once in a million times (see tree-traversal)
156+
// use std::cell::RefCell;
157+
// thread_local! {
158+
// pub static INFLATE: RefCell<zlib::Inflate> = RefCell::new(zlib::Inflate::default());
159+
// }
160+
//
161+
// INFLATE.with(|inflate| {
162+
// let mut inflate = inflate.borrow_mut();
163+
// let res = inflate
164+
// .once(&self.data[offset..], out)
165+
// .map(|(_status, consumed_in, consumed_out)| (consumed_in, consumed_out));
166+
// inflate.reset();
167+
// res
168+
// })
169+
zlib::Inflate::default()
170+
.once(&self.data[offset..], out)
171+
.map(|(_status, consumed_in, consumed_out)| (consumed_in, consumed_out))
165172
}
166173

167174
/// Decode an entry, resolving delta's as needed, while growing the `out` vector if there is not enough

0 commit comments

Comments
 (0)