Optifine is probably the culprit. My render distance is also 32 chunks btw.
Disabling optifine fixed the issue but I like optifine so I continued my research. I Have opened up the back of my cave to allow light in and that solved the issue. So It must be something to do with optifine "saving resources" by not rendering chunks that are further away in caves. Hence when I opened it up it was no longer classified as a cave and so the rendering error no longer happened.