Skip to content

Commit 4eb199f

Browse files
committed
refactor(abi/fastly): config store buffer adapts as best it can
1 parent 1f82a09 commit 4eb199f

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

internal/abi/fastly/hostcalls_guest.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,12 +2487,13 @@ alloc:
24872487
status := fastlyDictionaryGet(
24882488
d.h,
24892489
keyBuffer.Data, keyBuffer.Len,
2490-
prim.ToPointer(buf.Char8Pointer()),
2491-
buf.Cap(),
2490+
prim.ToPointer(buf.Char8Pointer()), buf.Cap(),
24922491
prim.ToPointer(buf.NPointer()),
24932492
)
2494-
if status == FastlyStatusBufLen && buf.NValue() > 0 {
2495-
n = int(buf.NValue())
2493+
// The Dictionary API cannot return the needed size with this error.
2494+
// Instead of perfectly adapting, we allocate the maximum length a value can have.
2495+
if status == FastlyStatusBufLen && n < dictionaryValueMaxLen {
2496+
n = dictionaryValueMaxLen
24962497
goto alloc // goto saves having to allocate a function closure and avoids having to duplicate the hostcall
24972498
}
24982499

@@ -2521,8 +2522,7 @@ func (d *Dictionary) Has(key string) (bool, error) {
25212522
if err := fastlyDictionaryGet(
25222523
d.h,
25232524
keyBuffer.Data, keyBuffer.Len,
2524-
prim.NullChar8Pointer(),
2525-
0,
2525+
prim.NullChar8Pointer(), 0,
25262526
prim.ToPointer(&npointer),
25272527
); err != FastlyStatusOK {
25282528
if err == FastlyStatusBufLen {

internal/abi/fastly/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,9 @@ func IsFastlyError(err error) (FastlyStatus, bool) {
185185
}
186186

187187
const (
188-
ipBufLen = 16 // known size for IP address buffers
189-
dnsBufLen = 256 // known size for "DNS" values, enough to hold the longest possible hostname or domain name
188+
ipBufLen = 16 // known size for IP address buffers
189+
dnsBufLen = 256 // known size for "DNS" values, enough to hold the longest possible hostname or domain name
190+
dictionaryValueMaxLen = 8192 // known size for maximum config store value https://docs.fastly.com/en/guides/about-edge-dictionaries#limitations-and-considerations
190191

191192
DefaultSmallBufLen = 128 // default size for "typically-small" values with variable sizes: HTTP methods, header names, tls protocol names, cipher suites
192193
DefaultMediumBufLen = 1024 // default size for values between small and large with variable sizes

0 commit comments

Comments
 (0)