chrysn / aiocoap

The Python CoAP library
Other
262 stars 119 forks source link

ExtensibleIntEnum: Guard against indefinite growth #263

Open chrysn opened 2 years ago

chrysn commented 2 years ago

ExtensibleIntEnum stores the singleton instance for every new variant it encounters. This is not an issue when used for Code (there are only 256 possible values), but for Option this means that a peer that produces all options in subsequent requests can permanently occupy 64k * size of OptionNumber memory -- not fatal on typical systems, but not ideal and a possible dealbreaker for highly constrained applications (which aiocoap is not really designed for but should still not rule out needlessly).

The likely way forward is to make the ad-hoc versions weak.

chrysn commented 2 years ago

The hard part about making ad-hoc versions weak is that users might also build instances during startup, assign properties and expect to recognize them by properties later (especially relevant to content formats which just switch over). Keeping them would be nontrivial, compatibility-wise.