Skip to content

Instantly share code, notes, and snippets.

@jayc971
Last active June 29, 2025 21:30
Show Gist options
  • Select an option

  • Save jayc971/92564c6249220b70442b64146ff8d6a2 to your computer and use it in GitHub Desktop.

Select an option

Save jayc971/92564c6249220b70442b64146ff8d6a2 to your computer and use it in GitHub Desktop.
code solution for go
build system was silently hanging during compilation instead of failing fast when circular dependencies existed. The dependency resolver was getting stuck in infinite loops rather than detecting cycles.
### What Happened:
```javascript
// These dependencies created a cycle:
const moduleDeps = [
"UserService>OrderService",
"OrderService>PaymentService",
"PaymentService>UserService" // Creates cycle!
];
// Build system kept trying to resolve, never terminating
// Developers waited 20+ minutes before killing builds
```
### Your Discovery Process:
1. **Symptom**: Builds randomly hanging on certain feature branches
2. **Investigation**: Added logging to dependency resolution
3. **Root Cause**: Cycle detection was missing from the topological sort
4. **Impact**: 5+ developers losing hours daily to hung builds
### The Fix:
```javascript
function detectCycle(graph) {
// Your solution: DFS with color marking
// White (0) = unvisited, Gray (1) = processing, Black (2) = done
if (dfs(node) && color[neighbor] === 1) {
throw new Error(`Circular dependency detected: ${cyclePath}`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment