Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: occasional panic when watched YAML files change #1246

Merged
merged 1 commit into from
Mar 12, 2024

Conversation

dinhlockt02
Copy link
Contributor

@dinhlockt02 dinhlockt02 commented Mar 11, 2024

This PR

At the moment, the yamlToJSON will convert []byte("") to "null". While "null" is a normal string, it will bypass all validator and lead to panic.

Related Issues

Fixes #1242

Notes

I found that sometime, the os.Readfile will return empty byte and no error, this will cause the yamlToJSON convert the rawData ("") to jsonData ("null").
Moreover, when I check the log, the watcher is reading file content a lot at a times for checking file changes, so it could be the reason why os.Readfile return empty byte?
image

Follow-up Tasks

I think we have to check the behavior of os.Readfile?

How to test

@dinhlockt02 dinhlockt02 requested a review from a team as a code owner March 11, 2024 23:48
Copy link

netlify bot commented Mar 11, 2024

Deploy Preview for polite-licorice-3db33c canceled.

Name Link
🔨 Latest commit c4a422f
🔍 Latest deploy log https://app.netlify.com/sites/polite-licorice-3db33c/deploys/65f074cd852c760008da480a

@dinhlockt02 dinhlockt02 changed the title Handle empty case for yaml conversion fix: Handle empty case for yaml conversion Mar 11, 2024
Copy link

codecov bot commented Mar 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.21%. Comparing base (1c530ab) to head (33a4503).
Report is 34 commits behind head on main.

❗ Current head 33a4503 differs from pull request most recent head c4a422f. Consider uploading reports for the commit c4a422f to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1246      +/-   ##
==========================================
+ Coverage   73.69%   77.21%   +3.51%     
==========================================
  Files          32       19      -13     
  Lines        3140     1549    -1591     
==========================================
- Hits         2314     1196    -1118     
+ Misses        717      272     -445     
+ Partials      109       81      -28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@toddbaert
Copy link
Member

toddbaert commented Mar 12, 2024

I bet that this is due to the way files are saved/changed on different systems. I believe when I save a file in vscode on my Linux machine, it results in multiple fs events, some of which have no content.

Thanks @dinhlockt02 for your effort. I will give this a review soon.

@toddbaert toddbaert requested review from beeme1mr and bacherfl March 12, 2024 14:41
Copy link
Contributor

@Kavindu-Dodan Kavindu-Dodan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for identifying the root cause. I think this is a good enough fix for the bug :)

Signed-off-by: Tran Dinh Loc <dinhlockt02@gmail.com>
Copy link
Member

@toddbaert toddbaert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@toddbaert
Copy link
Member

@dinhlockt02 Thanks so much for your contribution. The only change I will make is the PR title, so it might be a bit easier to understand in our release notes.

@toddbaert toddbaert changed the title fix: Handle empty case for yaml conversion fix: occasional panic when watched YAML file changes Mar 12, 2024
@toddbaert toddbaert changed the title fix: occasional panic when watched YAML file changes fix: occasional panic when watched YAML files change Mar 12, 2024
@toddbaert toddbaert merged commit 6249d12 into open-feature:main Mar 12, 2024
14 checks passed
@github-actions github-actions bot mentioned this pull request Mar 12, 2024
Kavindu-Dodan pushed a commit that referenced this pull request Mar 15, 2024
🤖 I have created a release *beep* *boop*
---


<details><summary>flagd: 0.9.1</summary>

##
[0.9.1](flagd/v0.9.0...flagd/v0.9.1)
(2024-03-15)


### 🐛 Bug Fixes

* **deps:** update module google.golang.org/protobuf to v1.33.0
[security] ([#1248](#1248))
([b2b0fa1](b2b0fa1))
* update protobuff CVE-2024-24786
([#1249](#1249))
([fd81c23](fd81c23))


### ✨ New Features

* serve sync.proto on port 8015
([#1237](#1237))
([7afdc0c](7afdc0c))


### 🧹 Chore

* move packaging & isolate service implementations
([#1234](#1234))
([b58fab3](b58fab3))
</details>

<details><summary>flagd-proxy: 0.5.1</summary>

##
[0.5.1](flagd-proxy/v0.5.0...flagd-proxy/v0.5.1)
(2024-03-15)


### 🐛 Bug Fixes

* update protobuff CVE-2024-24786
([#1249](#1249))
([fd81c23](fd81c23))


### 🧹 Chore

* move packaging & isolate service implementations
([#1234](#1234))
([b58fab3](b58fab3))
</details>

<details><summary>core: 0.8.1</summary>

##
[0.8.1](core/v0.8.0...core/v0.8.1)
(2024-03-15)


### 🐛 Bug Fixes

* occasional panic when watched YAML files change
([#1246](#1246))
([6249d12](6249d12))
* update protobuff CVE-2024-24786
([#1249](#1249))
([fd81c23](fd81c23))


### 🧹 Chore

* move packaging & isolate service implementations
([#1234](#1234))
([b58fab3](b58fab3))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] panic when yaml file watchers are updated
3 participants