Skip to content

Commit 39e3e1d

Browse files
committed
Closing client connections
1 parent b5a6001 commit 39e3e1d

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111
### Changed
1212
### Fixed
1313

14+
- Corrected the closing of client connections in ES index management functions [#132](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/132)
15+
1416
## [v0.3.0]
1517

1618
### Added
@@ -59,7 +61,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
5961
Previously, there was no sort order defined.
6062
- Db_to_stac serializer moved to core.py for consistency as it existed in both core and database_logic previously.
6163
- Use genexp in execute_search and get_all_collections to return results.
62-
- Added db_to_stac serializer to item_collection method in core.py.
64+
- Added db_to_stac serializer to item_collection method in core.py.
6365

6466
[Unreleased]: <https://github.com/stac-utils/stac-fastapi-elasticsearch/tree/v0.3.0...main>
6567
[v0.3.0]: <https://github.com/stac-utils/stac-fastapi-elasticsearch/tree/v0.2.0...v0.3.0>

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,29 +140,38 @@ def indices(collection_ids: Optional[List[str]]) -> str:
140140

141141

142142
async def create_collection_index() -> None:
143-
"""Create the index for Items and Collections."""
144-
await AsyncElasticsearchSettings().create_client.indices.create(
143+
"""Create the index for Collections."""
144+
client = AsyncElasticsearchSettings().create_client
145+
146+
await client.indices.create(
145147
index=COLLECTIONS_INDEX,
146148
mappings=ES_COLLECTIONS_MAPPINGS,
147149
ignore=400, # ignore 400 already exists code
148150
)
151+
await client.close()
149152

150153

151154
async def create_item_index(collection_id: str):
152-
"""Create the index for Items and Collections."""
153-
await AsyncElasticsearchSettings().create_client.indices.create(
155+
"""Create the index for Items."""
156+
client = AsyncElasticsearchSettings().create_client
157+
158+
await client.indices.create(
154159
index=index_by_collection_id(collection_id),
155160
mappings=ES_ITEMS_MAPPINGS,
156161
settings=ES_ITEMS_SETTINGS,
157162
ignore=400, # ignore 400 already exists code
158163
)
164+
await client.close()
159165

160166

161167
async def delete_item_index(collection_id: str):
162-
"""Create the index for Items and Collections."""
163-
await AsyncElasticsearchSettings().create_client.indices.delete(
168+
"""Delete the index for Items."""
169+
client = AsyncElasticsearchSettings().create_client
170+
171+
await client.indices.delete(
164172
index=index_by_collection_id(collection_id)
165173
)
174+
await client.close()
166175

167176

168177
def bbox2polygon(b0: float, b1: float, b2: float, b3: float) -> List[List[List[float]]]:

0 commit comments

Comments
 (0)