# Redis GO test cases donot have any file bytes

**URL:** <https://forum.codecrafters.io/t/redis-go-test-cases-donot-have-any-file-bytes/12264>\
**Category:** Challenges\
**Tags:** challenge:redis\
**Created:** [June 17, 2025, 12:39pm UTC](https://forum.codecrafters.io/t/redis-go-test-cases-donot-have-any-file-bytes/12264 "2025-06-17T12:39:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rony0000013](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rony0000013/32/13094_2.png) [@rony0000013](https://forum.codecrafters.io/u/rony0000013)\
**Post date:** [June 17, 2025, 12:39pm UTC](https://forum.codecrafters.io/t/redis-go-test-cases-donot-have-any-file-bytes/12264/1 "2025-06-17T12:39:20Z")

</div>

I’m stuck on Stage #jz6.

I’ve tried changing code even printing the file bytes contents still shows file is empty.

Here are my logs:

```auto
[tester::#JZ6] Running tests for Stage #JZ6 (RDB Persistence - Read a key)
[tester::#JZ6] Created RDB file with a single key: ["banana"]
[tester::#JZ6] $ ./your_program.sh --dir /tmp/rdbfiles4247079374 --dbfilename blueberry.rdb
[your_program] Opening file: /tmp/rdbfiles4247079374/blueberry.rdb
[your_program] File bytes: 
[your_program] Failed to open database: file is too small: 
[your_program] Server started on port 6379
[tester::#JZ6] client: $ redis-cli KEYS *
[your_program] Client connected: [::1]:59688
[tester::#JZ6] Expected command to be "banana", got "strawberry"
[tester::#JZ6] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)

```

And here’s a snippet of my code:

```go
func Open(dir string, dbfilename string) (metadata map[string]string, databases map[uint8]resp.Database, err error) {
	if dir == "" {
		dir = "./"
	}
	if dbfilename == "" {
		dbfilename = "dump.rdb"
	}

	filePath := filepath.Join(dir, dbfilename)
	fmt.Printf("Opening file: %v\n", filePath)
	if _, err := os.Stat(filePath); os.IsNotExist(err) {
		return nil, nil, fmt.Errorf("file does not exist: %v", filePath)
	}
	file, err := os.Open(filePath)
	if err != nil {
		return nil, nil, fmt.Errorf("error opening file: %v", err)
	}
	defer file.Close()

	fileBytes, err := io.ReadAll(file)
	if err != nil {
		return nil, nil, fmt.Errorf("error reading file: %v", err)
	}
	fmt.Printf("File bytes: % X\n", fileBytes)

	if len(fileBytes) < 8 {
		return nil, nil, fmt.Errorf("file is too small: % X", fileBytes)
	}

```

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [June 17, 2025, 12:46pm UTC](https://forum.codecrafters.io/t/redis-go-test-cases-donot-have-any-file-bytes/12264/3 "2025-06-17T12:46:32Z")

</div>

Hey @rony0000013, could you [upload your code to GitHub](https://docs.codecrafters.io/features/publish-to-github) and share the link? It will be much easier to debug if I can run it directly.

---

<div class="post-metadata">

**Author:** ![rony0000013](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rony0000013/32/13094_2.png) [@rony0000013](https://forum.codecrafters.io/u/rony0000013)\
**Post date:** [June 17, 2025, 1:45pm UTC](https://forum.codecrafters.io/t/redis-go-test-cases-donot-have-any-file-bytes/12264/4 "2025-06-17T13:45:31Z")

</div>

[https://git.codecrafters.io/732b0d1224c2caae](https://git.codecrafters.io/732b0d1224c2caae)

> **[GitHub - rony0000013/redis-go](https://github.com/rony0000013/redis-go)**
>
> Contribute to rony0000013/redis-go development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![EshaanAgg](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/eshaanagg/32/399_2.png) [@EshaanAgg](https://forum.codecrafters.io/u/EshaanAgg)\
**Post date:** [June 17, 2025, 7:34pm UTC](https://forum.codecrafters.io/t/redis-go-test-cases-donot-have-any-file-bytes/12264/6 "2025-06-17T19:34:05Z")

</div>

My guess would be that the problem is most likely not related to the RDB content (used the tester to check the file content, and it is creating the file correctly!), but due to the fact that your server should kill itself and shutdown gracefully on receiving `SIGTERM` (`CTRL` + `C`). Here are the tester logs that show the same (as you can see at the end of stage `201`).

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/a/a2decb7026e730078d153346279bf60a76989765.png)

I even tried to manually start the server via `your_program.sh` and then kill it with `CTRL + C`, but the same doesn’t work.

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/c/c46dca4bbd4c03cada0aba6b8b35bea5f897c76b.png)

If your server does not shutdown gracefully in such a situation, then when the tests are run in quick succession, it is possible that the processes for the different tests try to share the same resources (ports, directories, files), and thus you get this error. Even in the case of a single test, this can point to some incorrect synchronisation or improperly managed resources (goroutines), that may be causing the data race.

---

<div class="post-metadata">

**Author:** ![rony0000013](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rony0000013/32/13094_2.png) [@rony0000013](https://forum.codecrafters.io/u/rony0000013)\
**Post date:** [June 18, 2025, 5:25am UTC](https://forum.codecrafters.io/t/redis-go-test-cases-donot-have-any-file-bytes/12264/8 "2025-06-18T05:25:21Z")

</div>

I updated my code to close server on getting any SIGTERM, os.KILL, os.Interrupt commands still the file I am reading is empty

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/b/b08e8b7bc55b1589e0d3256653d83595602a46cc.png)  
by the way I am coding and testing my code in windows with command “go run app/main.go”

---

<div class="post-metadata">

**Author:** ![EshaanAgg](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/eshaanagg/32/399_2.png) [@EshaanAgg](https://forum.codecrafters.io/u/EshaanAgg)\
**Post date:** [June 18, 2025, 5:43am UTC](https://forum.codecrafters.io/t/redis-go-test-cases-donot-have-any-file-bytes/12264/10 "2025-06-18T05:43:13Z")

</div>

Ahh nice! My bad. I just looked at the code again, and the problem is actually in the `main` function:

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/b/b36f9d3a491e688e14708e20e0a383103fbcabf5.png)

If the `dir` and `dbfilename` are provided, you are just supposed to try to access them and not create the directories and the file, cause in the process you end up overwriting them and their content, and thus you get the no bytes in the file error.

After commenting out the same, the content is read correctly, and now the error changes:

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/8/8fe83ec8113fecc9b1dea071b98d9d71e8e779d7.png)  
So you may want to debug your checksum calculation now!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [June 23, 2025, 6:10am UTC](https://forum.codecrafters.io/t/redis-go-test-cases-donot-have-any-file-bytes/12264/12 "2025-06-23T06:10:49Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
